core-data

Managed Objects have different id when fetched

雨燕双飞 提交于 2020-01-04 13:47:42
问题 im working with coredata and there is a concept that im not getting; i've 2 managed objects ACConversation and ACMessages with a one to many relationship, so i'm saving a message associated to a conversation and trying to fetch them back based on: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.conversation = %@", self.conversation]; but the id associated to the object is different (it seems more a memory address) and with the above predicate it doesnt fetch anything: 2013-01

Is it possible to 'force' the app to accept a new model version even if it means overwriting the existing one?

戏子无情 提交于 2020-01-04 13:32:46
问题 Firstly, I'm not 100% clued up on Core Data, but I do what I can. So I've implemented Lightweight Migration for when the app is updated, but recently this has failed, i.e. the app crashes after trying to access the local DB. I currently assume that the reason is because of some mix up with the model versions, but even if not so, I think my question is still valid: Is there a way, when updating/upgrading an app, to ignore the Core Data migration process and force the app to use the latest

Core Data Integer changing value?

戏子无情 提交于 2020-01-04 13:26:28
问题 i have a problem with core data storing integer (i chose int16 because they have a maximum of 6 signs). my model holds Entity: 'Expense' the attribute in question is: @property (nonatomic, retain) NSNumber * month; it was automatically implemented as NSNumber by Xcode (Editor > createManagedmodelsubclass) month holds an short identifier for every month. example 201203 //would be march of 2012 i store new entities with this snippet: [newExpense setValue:monthNumber forKey:@"month"]; which

Core data. NSPredicate issue using constant literals as names of properties

 ̄綄美尐妖づ 提交于 2020-01-04 12:45:00
问题 I have NSManagedObject with properties. Suppose that one property it is: @property (retain, nonatomic) NSString *city; For fetching data form core data I always use NSPredicate . The predicate looks like below: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", @"city", @"San Francisco"]; But the problem here that the project use key "city" as undefined key in meaning like a constant. So lets suppose that I use key "city" in my app 1000 times, so then I need to replace all

NSOperationQueue and NSFetchedResultsController

女生的网名这么多〃 提交于 2020-01-04 11:05:29
问题 i use a combination of queue and resultscontroller to update and display some coredata objects. in my uitableviewcontroller i call every X second a method in my main controller object. [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(test:) userInfo:nil repeats:YES]; } - (void)test:(NSTimer*)theTimer { [[MainController instance] updatePersons]; } In this method a custom NSOperation object will be added to my main Q. - (BOOL)updatePersons { UpdatePersonsOperation* u = [

Illegal attempt to establish a relationship between objects in different contexts

旧巷老猫 提交于 2020-01-04 10:44:51
问题 I have two managedobjectcontext I fetch object from managedobjectcontext1 and want two save it in the second object context while try to do that I get the error: "Illegal attempt to establish a relationship between objects in different contexts". The code I use NSError * error; NSPersistentStoreCoordinator *persistentStoreCoordinator_OLD; NSPersistentStoreCoordinator *persistentStoreCoordinator_NEW; NSManagedObjectModel *managedObjectModel_OLD; NSManagedObjectModel *managedObjectModel_NEW;

Illegal attempt to establish a relationship between objects in different contexts

三世轮回 提交于 2020-01-04 10:43:30
问题 I have two managedobjectcontext I fetch object from managedobjectcontext1 and want two save it in the second object context while try to do that I get the error: "Illegal attempt to establish a relationship between objects in different contexts". The code I use NSError * error; NSPersistentStoreCoordinator *persistentStoreCoordinator_OLD; NSPersistentStoreCoordinator *persistentStoreCoordinator_NEW; NSManagedObjectModel *managedObjectModel_OLD; NSManagedObjectModel *managedObjectModel_NEW;

Core Data not automatically calling value transformer when getting / setting attribute directly in code

风流意气都作罢 提交于 2020-01-04 09:46:46
问题 If I understand correctly, the idea behind Core Data transformable attributes is: implement an NSValueTransformer subclass with returns [NSData class] in +transformedValueClass along with its implementation for transformation register the transformer in +load or +initialize set an entity's attribute as transformable set a name for your transformer (the name you used to register it) in the xcode model editor for the attribute. At this point, I'd expect that accessing or setting the attribute

Core Data not automatically calling value transformer when getting / setting attribute directly in code

佐手、 提交于 2020-01-04 09:42:13
问题 If I understand correctly, the idea behind Core Data transformable attributes is: implement an NSValueTransformer subclass with returns [NSData class] in +transformedValueClass along with its implementation for transformation register the transformer in +load or +initialize set an entity's attribute as transformable set a name for your transformer (the name you used to register it) in the xcode model editor for the attribute. At this point, I'd expect that accessing or setting the attribute

Core Data : inserting Objects crashed in global queue [ARC - iPhone simulator 6.1]

守給你的承諾、 提交于 2020-01-04 06:23:28
问题 I have a very simple Core Data demo, in which there is only one button. When I click the 'run' button, the App creates 10,000 objects in a for-loop, which is running in the global queue . Update for more detail : If I put the for-loop in main thread, it runs well. Update for my intent : I know that MOC is not thread-safe, but according to the Apple doc, we can also use serial queue to access the MOC, and the serial queue uses more than one threads. Here I create the Core Data stack: #pragma