The following (somewhat contrived) code works when Swift Optimization Level is set to None [-Onone] (default for debug):
let nsa = NSArray(array: ["foo", "bar"])
let a = nsa as [String]
But the app crashes (crash log) during run-time when set to Fastest [-O] (default for release).
I luckily discovered I can work around the issue by doing this:
let a = nsa as [AnyObject] as [String]
My question is two-fold:
- Could you help me understand why this is happening?
- Is there a better way to convert an NSArray to an Array?
UPDATE
This does seem to be a bug. I have not reported it to Apple. If someone else would like to take the time to do so, please do!