In Obj-C, you can use asserts like this:
NSAssert([self foo], @"Something something");
Similarly in Swift:
In Obj-C, asserts are controlled by
Enable Foundation Assertions in Xcode Build Settings) which is default to
NO in release builds.
But in Swift, asserts are controlled by the Swift optimization level. With a release build — which defaults
Swift Compiler - Code Generation >
Optimization Level) to
assert() doesn't run. It runs with
It's not complicated once we realise these are 2 different flags, but it's still a good practice to only run code which has no side effects with an assert to present such errors.