ios - Lazy load CoreData relationship -


what correct approach lazy loading coredata relationships?

say have project object , projectfilter object may or may not exist, work expected?

- (projectfilter *)filter {     [self willaccessvalueforkey:@"filter"];     projectfilter *filter = [self primitivevalueforkey:@"filter"];     [self didaccessvalueforkey:@"filter"];      if (!filter) {         filter = [nsentitydescription insertnewobjectforentityforname:@"projectfilter" inmanagedobjectcontext:self.managedobjectcontext];         self.filter = filter;     }     return filter; } 

this terrible idea , shouldn't it.

in simple core data stack can have running on main thread. app gets more complex need have background context. if have multiple context writing core-data @ same time can merge conflicts. can tell core-data auto-resolve merged conflicts - isn't great solution because guaranteed lose data way. common solution have single queue writing , use main thread queue reading.

in setup hiding fact writing core data. accessing project.filter cause write in core data. if trying manage when , writing core-data very hard developer recognize write.

even if core-data not using setup important developer know when writing core-data. after write have save. after write might need aware affect fetched results controller. after write can merged conflicts.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -