Search code examples
swiftcore-datacrashint32

Crash with reading Int32 with Swift 2 and core data


Trying to read data in Swift (2) from an NSDictionary with Xcode 7.3 I came across the infamous EXC_BAD_INSTRUCTION (code=EXCI386_INVOP,subcode=0X0) error when trying this:

let aDict = data as! NSDictionary
car.tempo = aDict["tempo"] as! Int32

No compiler warnings though. I am aware that there were issues with Xcode, Swift and Int32s in the past. Any suggestions how to handle this better? TIA!

Since it wasn't clear maybe - data as shown above is guaranteed to contain data from a plist file and aDict["tempo"] is an NSNumber.


Solution

  • Thanks for the suggestions. There was no issue regarding the data and if so there should not have been a EXC_BAD_INSTRUCTION (code=EXCI386_INVOP,subcode=0X0) error. This is apparently a bug in Xcode and I will file a radar. Reformulating like below does work in Xcode 7.3 as NSNumber gets unwrapped as an Int32:

    car.tempo = (aDict["tempo"]?.intValue)!
    

    Thanks again!