0

I have a core data entity that stores information about transactions on various accounts. The API I am using pulls back data on the individual transactions for a given account but does not return the accountID. The account ID is specified as a parameter in the the post request to the API. When the data is returned, I want to do the entity mapping from RestKit and also set the account ID of each object to the account ID sent in the API request. I have the entity mapping setup and working fine but I'm having difficulty figuring out how to set the accountID of the entity since it is not returned from the API.

I found this question yesterday that says you can set values in the - (void)willSave method of the NSManagedObject subclass, but I'm not sure how to pass the accountID to the - (void)willSave method.

I have verified I can set the accountID statically in the NSManagedObject subclass, but I want to do it based on the value for the account sent in the body of my post. Here is my code to set it statically:

- (void)willSave {
[super willSave];


if ([self.accountID length]==0){
    [self setPrimitiveValue:@"123456789" forKey:@"accountID"];

}

}

Can anyone provide further guidance on how to set the accountID at the same time RestKit saves the rest of the data from the API request?

Community
  • 1
  • 1
David L
  • 4,347
  • 3
  • 18
  • 30
  • It's actually a little unclear where you specify the account id. Generally I'd expect it to be in the URL, but your last line indicates otherwise. If it's actually in the post body then you have issues and you would just need to extract the id in the success block from the sent object and set it to the mapped results. – Wain Jun 17 '14 at 07:23
  • Also not clear why you're using POST when you are just trying to get some data back... – Wain Jun 17 '14 at 07:34
  • @Wain, thanks for your response. Is there a good example of how to do that in the success block? It looks to me like the success block is only called once for the post so I'm still confused about how to set the accountID for each item returned from the post. – David L Jun 17 '14 at 13:59
  • Yes, it is only called once. You can iterate over the contents of the mapping result and update each item. – Wain Jun 17 '14 at 14:28

0 Answers0