ios - RestKit Core Data 'managedObjectStore is nil' -
i don't know if root cause of issue or not, when making request using
appropriateobjectrequestoperationwithobject:nil method:rkrequestmethodget path:path parameters:nil
it work, , when trying map response gives me warning:
w restkit:rkobjectmanager.m:635 asked create `rkmanagedobjectrequestoperation` object, managedobjectstore nil.
followed by:
coredata: error: failed call designated initializer on nsmanagedobject class 'container'
i assume because not matching request against managed object mapping, can't figure out why. creating persistent store using code:
// initialize managed object store nsmanagedobjectmodel *managedobjectmodel = [nsmanagedobjectmodel mergedmodelfrombundles:nil]; rkmanagedobjectstore *managedobjectstore = [[rkmanagedobjectstore alloc] initwithmanagedobjectmodel:managedobjectmodel]; nserror *error = nil; [managedobjectstore createpersistentstorecoordinator]; bool success = rkensuredirectoryexistsatpath(rkapplicationdatadirectory(), &error); if (! success) { rklogerror(@"failed create application data directory @ path '%@': %@", rkapplicationdatadirectory(), error); } nsstring *path = [rkapplicationdatadirectory() stringbyappendingpathcomponent:@"store.sqlite"]; nspersistentstore *persistentstore = [managedobjectstore addsqlitepersistentstoreatpath:path fromseeddatabaseatpath:nil withconfiguration:nil options:nil error:&error]; if (! persistentstore) { rklogerror(@"failed adding persistent store @ path '%@': %@", path, error); } [managedobjectstore createmanagedobjectcontexts];
the appropriate mapping/response descriptor:
rkentitymapping *containermapping = [rkentitymapping mappingforentityforname:@"container" inmanagedobjectstore:managedobjectstore]; [containermapping addattributemappingsfromdictionary:@{ @"id" : @"containerid", @"name" : @"name", @"public" : @"ispublic", @"user": @"userid", }]; containermapping.identificationattributes = @[@"containerid"]; responsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:containermapping method:rkrequestmethodany pathpattern:nil keypath:@"containers" statuscodes:rkstatuscodeindexsetforclass(rkstatuscodeclasssuccessful)];
it seems have not configured object manager reference managed object store. should done when create object manager:
objectmanager.managedobjectstore = managedobjectstore;
without restkit falls using plain object operations everything.
note: if you're logging warnings see asked create rkmanagedobjectrequestoperation object, managedobjectstore nil
in log output.
Comments
Post a Comment