Lab Notes - Technical iOS

Swift - fatalError with Switch Statements

A quick write up of this because it was not obvious to find... it is not in The Swift Programming Language guide (at present), however you can find it in some of Apples sample code.

In Swift all switch statements must be exhaustive. To satisfy this requirement I had a default case, but based on the logic of how the program worked I knew that it should never be called.

In general in this situation it is a good idea to make sure we fail using an assert so that we will catch any problems during development.

iOS Number Entry Validation

It is important to validate data entered by users both from a programming point of view and a good user experience. If we do not validate the values then we have to handle invalid data in logic later on, which is often more work, to avoid bugs and issues. For the end user this will impact them when using the app as they will then have navigate back from what they are now doing in order to edit and correct the invalid data. Validating the value at the point of entry and giving meaningful error messages also helps the user by cutting down on simple typing mistakes.