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?