ios - Update CoreData Objects with NSFetchedResultsController -


i made app uses core data , fetched results controller.

i can add coredata objects , delete them. want update coredata object via fetched results controller. know have fetch objects , can change it. because i'm still learning don't know how this. i'd ask how this?

when fetch coredata, if modify results update actual value within coredata when save it.

you'll want first perform fetch:

nsfetchrequest *request = [[nsfetchrequest alloc] init]; [request setentity:[nsentitydescription entityforname:@"entity" inmanagedobejctcontext:moc]]; nserror *error = nil; nsarray *results = [moc executefetchrequest:request error:&error];  // error handling code 

once have results, can modify individual records...

myentity *entity = [results objectatindex:0]; entity.title = @"updated attribute"; // save context [moc save:&error]; 

edit: in swift, along lines of following:

let appdelegate = uiapplication.sharedapplication().delegate appdelegate var moc = appdelegate.managedobjectcontext!  var fetchrequest = nsfetchrequest() fetchrequest.entity = nsentitydescription.entityforname("entity", inmanagedobjectcontext: moc)  var error: nserror? var results = moc.executefetchrequest(fetchrequest, error: &error)  // error handling code  var entity: myentity = myentity() entity.title = "updated attribute"  moc.save(&error) 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -