ios - In Apple's 'TaggedLocations' Core Data example a ivar NSManagedObjectContext gets a value but I can't find where? -


in apple's core data example 'taggedlocations' have viewcontroller declares in header

@property (nonatomic) nsmanagedobjectcontext *managedobjectcontext;   

then in main file never set context equal or initialize or allocate anywhere. use in fetch request retrieve results. makes sense given context "scratchpad' objects persistent store.

however, don't see how they're declaring or persistent store either. in previous core data examples i've seen people create instances of appdelegate , access it's context , store, makes sense because in example entire core data stack there.

this snippet of code apple's example, on looking?

/*  fetch existing events.  create fetch request event entity; add sort descriptor; execute fetch.  */ nsfetchrequest *request = [[nsfetchrequest alloc] initwithentityname:@"aplevent"]; [request setfetchbatchsize:20];  // order events creation date, recent first. nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"creationdate" ascending:no]; nsarray *sortdescriptors = @[sortdescriptor]; [request setsortdescriptors:sortdescriptors];  // execute fetch.  //not sure how they're excuting fetch request on self.managedobjectcontext? seems nil unintialized context //to-do test value of context nserror *error; nsarray *fetchresults = [self.managedobjectcontext executefetchrequest:request error:&error]; if (fetchresults == nil) {     // replace implementation code handle error appropriately.     // abort() causes application generate crash log , terminate. should not use function in shipping application, although may useful during development.     nslog(@"unresolved error %@, %@", error, [error userinfo]);     abort(); } 

link apple's example https://developer.apple.com/library/ios/samplecode/taggedlocations/introduction/intro.html#//apple_ref/doc/uid/dts40008914

thanks ahead input!

whenever project created core data , in app delegate u can these,

@property (readonly, strong, nonatomic) nsmanagedobjectcontext *managedobjectcontext; @property (readonly, strong, nonatomic) nsmanagedobjectmodel *managedobjectmodel; @property (readonly, strong, nonatomic) nspersistentstorecoordinator *persistentstorecoordinator;

and can external file too, data going store.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -