Friday, 20 March 2015

Restkit + swift handle null value

The error is:

W restkit.object_mapping:RKMappingOperation.m:484 Coercing NSNull value to nil in shouldSetValue:atKeyPath: -- should be fixed.

because server side return me a json like this:

                "id": 241,
                "username": "username",
                "fullName": "Full Name",
                "profilePicture": NULL

My model is defined like this:

The place throws this error is:

            [self.destinationObject setValue:value forKeyPath:attributeMapping.destinationKeyPath];

I can see any issue with that, which is assign null to a property of an object. 

But, if you pay a little attention on the error log, it is going to assign NSNull to nil.

Stupid obj-c and swift can not convert this two type from each other.

My solution is :

For error properties,  make them as NSObject:

No comments:

Post a comment