ios - RESTKIT : deserialize JSON with not all relationship attribute -
i tried deserialize json :
{"id":1234, "content": "hi, message", "datesaved":"10/04/2015 11:00", "user":{"id":12}}
model :
class message: nsmanagedobject { @nsmanaged var content: string @nsmanaged var datesaved: nsdate @nsmanaged var id: nsnumber @nsmanaged var user: user } class user: nsmanagedobject { @nsmanaged var id: nsnumber @nsmanaged var login: string @nsmanaged var mobile: string @nsmanaged var password: string @nsmanaged var picture: nsdata @nsmanaged var messages: nsset }
the user saved in ios data base, don't need send data server. problem both rkrelationshipmapping
, rkconnectiondescription
seem not done kind of works : first works complete objects, can directly operate coredata ; second 1 can used identifier , not object
i can not change way server serialize objects json, because other android app works kind of json
somebody knows how solve issue?
ok figured out. have forgotten set method addattributemappingsfromdictionary
rkrelationshipmapping
:
let messageattributesmapping = [ "id": "id", "content": "content", "datesaved": "datesaved" ] extension message { class func mappingresponse(managedobjectstore: rkmanagedobjectstore) -> rkmapping { let messagemapping = rkentitymapping(forentityforname: "message", inmanagedobjectstore: managedobjectstore) messagemapping.identificationattributes = ["id"] messagemapping.addattributemappingsfromdictionary(messageattributesmapping) let usermapping = rkentitymapping(forentityforname: "user", inmanagedobjectstore: managedobjectstore) usermapping.identificationattributes = ["id"] usermapping.addattributemappingsfromdictionary(["id" : "id"]) messagemapping.addpropertymapping(rkrelationshipmapping(fromkeypath: "user", tokeypath: "user", withmapping: usermapping)) return messagemapping } }
this solution works deserialize json, still wondering if should try use rkconnectiondescription
, seemed built relationship have id?