I'm aware of the following Swift syntax forms which, when they fail, cause a runtime error / illegal instruction:
var x: Foo! // implicit unsafe unwrap
x as! y // unsafe downcast
optionalValue! // explicit unsafe unwrap
I want to remove as many as possible of these unsafe expressions from my program, and replace them with safe alternatives.
To remove these unsafe expressions, I first need to identify them. My naive approach so far has been to search for !
, and ignore all the false positives like logical negation. What more reliable ways exist? For example:
- Is there a comprehensive list of all Swift syntax forms which are unsafe? I'm guessing my list above is not comprehensive.
- Is there an Xcode or compiler flag to turn these operators into compiler warnings or compiler errors?
- Is there a linter I can run which will do this job?