Sandeep
Sandeep

Reputation: 21154

Updating the attribute of managed object locally in coredata and restkit

I have been struggling with the RestKit since 15 days now. Once I receive the data from remote, I would also be like to be able to edit the attributes locally and save.

I tried with few different approaches but none seem to be working;

 user.attribute = @"new valuel";
[[[RKObjectManager sharedManager].objectStore managedObjectContextForCurrentThread] save:&error];

        if(error)       
             NSLog(@"Error saving %@", error);

Second approach was to assign the value to the instance itself and save;

user.attribute = @"new valuel";
[user.managedObjectContext save:&error ];
NSlog(@"%@", error)

Another try,

[[RKObjectManager sharedManager].objectStore save:&error];

It seems I cannot get the pointer to the context. How is it possible to get the pointer or may be to save the object or is it not possible entirely ? None of these save into the database nor raise any error. What is the problem here ?

Upvotes: 2

Views: 2255

Answers (1)

user1223278
user1223278

Reputation:

I have the same problem. I also was trying your steps and then opened the database with a pluging of firefox and I could check that db is not updating.

Will let you know if I arrive to any final solution...

Update:

I finally got my code working adding the method refreshObject:mergeChanges. Finally my code, is something like this:

   // Make changes in managedObjectYouWantToSave 
   [managedObjectYouWantToSave.managedObjectContext refreshObject:managedObjectYouWantToSave mergeChanges:YES];
   [managedObjectYouWantToSave.managedObjectContext save:&error];

Upvotes: 4

Related Questions