Reputation: 3640
I have a Core Data class which is being populated via a JSON rest API call using Swift.
I can parse the dictionary without any problems for strings, but cannot parse the ID field which is an Int32.
My code is:
class Job: NSManagedObject {
@NSManaged var id: Int32
}
if let id = resultDict["JobID"] as? NSNumber {
job.id = Int32(id) // THIS LINE IS CAUSING THE ERROR
}
The error that I'm getting when trying to build is: 'Could not find an overload for 'init' that accepts the supplied arguments"
Upvotes: 0
Views: 295
Reputation: 42345
Int32
doesn't have an initializer that takes an NSNumber
. You can use the intValue
property of NSNumber
directly though; it returns an Int32
:
job.id = id.intValue
Upvotes: 1