objective c - fetch data from a RESTful API into Core Data -
hello can t fetch localdatabase json restapi
i want data website : http://barcelonaapi.marcpous.com/bus/stations.json
i'm using restkit 0.20
here code in appdelegate :
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { nsurl *baseurl = [nsurl urlwithstring:@"http://barcelonaapi.marcpous.com/bus/stations.json"]; rkobjectmanager *objectmanager = [rkobjectmanager managerwithbaseurl:baseurl]; // initialize managed object model bundle nsmanagedobjectmodel *managedobjectmodel = [nsmanagedobjectmodel mergedmodelfrombundles:nil]; // initialize managed object store rkmanagedobjectstore *managedobjectstore = [[rkmanagedobjectstore alloc] initwithmanagedobjectmodel:managedobjectmodel]; objectmanager.managedobjectstore = managedobjectstore; // complete core data stack initialization [managedobjectstore createpersistentstorecoordinator]; nsstring *storepath = [rkapplicationdatadirectory() stringbyappendingpathcomponent:@"busdb.sqlite"]; nsstring *seedpath = [[nsbundle mainbundle] pathforresource:@"rkseeddatabase" oftype:@"sqlite"]; nserror *error; nspersistentstore *persistentstore = [managedobjectstore addsqlitepersistentstoreatpath:storepath fromseeddatabaseatpath:seedpath withconfiguration:nil options:nil error:&error]; nsassert(persistentstore, @"failed add persistent store error: %@", error); // create managed object contexts [managedobjectstore createmanagedobjectcontexts]; // configure managed object cache ensure not create duplicate objects managedobjectstore.managedobjectcache = [[rkinmemorymanagedobjectcache alloc] initwithmanagedobjectcontext:managedobjectstore.persistentstoremanagedobjectcontext]; //------------------------end initilize restkit-------------------------------- rkentitymapping *buslistmapping = [rkentitymapping mappingforentityforname:@"bus" inmanagedobjectstore:managedobjectstore]; buslistmapping.identificationattributes = @[ @"streetname" ]; [buslistmapping addattributemappingsfromdictionary: @{ @"id": @"busid", @"street_name": @"streetname", @"city": @"city" } ]; rkresponsedescriptor *buslistresponsedescriptor = [rkresponsedescriptor responsedescriptorwithmapping:buslistmapping method:rkrequestmethodany pathpattern:nil keypath:@"data.tmbs" statuscodes:nil]; [objectmanager addresponsedescriptor:buslistresponsedescriptor]; return yes;
}
i've created entity model named bus coredata. when check localdatabase in device, there busdb.sqlite, not other 1 !!
Comments
Post a Comment