I want to fetch JSON data from my server and manipulate it upon launch. In Objective-C, I have used this #define code to convert NSNull to ni
This could be what you are looking for:
func nullToNil(value : Any?) -> Any? {
if value is NSNull {
return nil
} else {
return value
}
}
people.age = nullToNil(peopleDict["age"])
I would recommend, instead of using a custom conversion function, just to cast the value using as?:
people.age = peopleDict["age"] as? Int
If the value is NSNull, the as? cast will fail and return nil.