nsmanagedobject

Core data find-or-create most efficient way

给你一囗甜甜゛ 提交于 2019-12-18 15:34:53
问题 I have around 10000 objects of entity ' Message '. When I add a new ' Message ' i want to first see whether it exists - and if it does just update it's data, but if it doesn't to create it. Right now the "find-or-create" algorithm works with by saving all of the Message objects ' objectID ' in one array and then filtering through them and getting the messages with existingObjectWithID:error: This works fine but in my case when I fetch an 'Message' using existingObjectWithID : and then try to

Sort CoreData results using NSPredicate in Swift

扶醉桌前 提交于 2019-12-18 15:09:09
问题 I'm currently writing a simple phone book app in Swift and need to sort the results from a CoreData query. Basically, I set up an NSManagedObject called "Directory", with the appropriate field names in - e.g. "name_f" is the user's name. The names in the CoreData database that is queried are in alphabetical order. However, although the first search returns the results in alphabetical order, further searches sometimes aren't after the database has been queried by other areas of the program. I

NSManagedObjectModel initWithContentsOfURL returns nil eventhough the modelURL is valid

烈酒焚心 提交于 2019-12-18 14:12:10
问题 my NSManagedObjectModel is returning nil eventhough the path is correct. NSString *modelKey = [NSString stringWithFormat:@"/%@/Model", name]; NSString *modelPath = [((Configuration *)[Configuration shared]) stringEntry:modelKey]; NSURL *modelURL = nil; if ( ! [modelPath contains:@"://"] ) { modelPath = PathForBundleResource( modelPath ); modelURL = [NSURL fileURLWithPath:modelPath]; } NSManagedObjectModel *m = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSString

CoreData error driving me crazy… CoreData: Serious application error. An exception caught from delegate of NSFetchedResultsController

谁都会走 提交于 2019-12-18 10:55:26
问题 My application has two tab bars... Each takes the user to a tableviewcontroller that presents him with a list of items. The first view lets the user record entries in the database. The other tab/view reads from the database and presents those items to the user as well, however, no updates are made to the coreData/persistant store from this second view. When I add a new item via the first viewcontroller, it shows up perfectly in the view. However, as soon as I tap on the other tab bar to see

Can someone explain this @synthesize syntax?

 ̄綄美尐妖づ 提交于 2019-12-17 20:28:56
问题 I'm following the example Navigation View template with core data in the latest iOS SDK. In the rootViewController.m file I see this in the @synthesize line: @synthesize fetchedResultsController=fetchedResultsController_, managedObjectContext=managedObjectContext_; Where the header file is: @private NSFetchedResultsController *fetchedResultsController_; NSManagedObjectContext *managedObjectContext_; } @property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; @property

Subclassing NSManagedObject with swift 3 and Xcode 8 beta

ぐ巨炮叔叔 提交于 2019-12-17 18:18:21
问题 I've began to try use Core data with swift 3 and Xcode 8 beta. When I try to generate NSManagedObject subclasses from core data model and Create NSManagedObject subclass… option in Editor menu, Xcode 8 beta generates three files one of them is _COREDATA_DATAMODELNAME_ +CoreDataModel.swift with the following content: import Foundation import CoreData ___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES_IMPLEMENTATIONS___ In addition, the content of this file shows two warnings: Expressions are not

How can I create instances of managed object subclasses in a NSManagedObject Swift extension?

两盒软妹~` 提交于 2019-12-16 22:47:29
问题 When creating an extension helper to NSManagedObject to create a new managed object subclass, swift provides the Self type to mimic instancetype which is great, but i can't seem to typecast from AnyObject . The below code does not compile with error 'AnyObject' is not convertible to 'Self' Help? extension NSManagedObject { class func createInContext(context:NSManagedObjectContext) -> Self { var classname = className() var object: AnyObject = NSEntityDescription.insertNewObjectForEntityForName

Core data inserting rows and saving issue

倖福魔咒の 提交于 2019-12-14 03:59:39
问题 I´m having some problems when saving data in core data and also with the rows organization and for better understanding of what my problem is, i´m going to explain what i have: I have a main tableview working with dynamic rows, in this tableview i have a + button, whenever the + button is pressed, a tableview appears inside a popover were the user can choose the "type of cell" to insert in the main tableview. The "type of cell" are custom cells and they have they´re one class and xib file.

Failed to call designated initializer on NSManagedObject class 'Item'

最后都变了- 提交于 2019-12-13 19:05:38
问题 I am using core-data to add/delete 'Items' (NSManagedObject) to the model. However, I am receiving the error in the title: Code: Failed to call designated initializer on NSManagedObject class 'Item' I would really appreciate it if you could tell me where I am going wrong. I presume that the problem is to do with initialising Item. RootViewController.m - (void)AddNew { CDManager *manager = [[CDManager alloc] initWithManagedObjectContext:[self managedObjectContext] andDelegate:self]; [manager

What happens when I don't write accessor methods for Core Data scalar property?

て烟熏妆下的殇ゞ 提交于 2019-12-13 19:02:59
问题 I am working with several Core Data entities that I used to generate NSManagedObject subclasses, and at the time I generated those classes I selected the "Use scalar properties for primitive data types" option. As expected, integer attributes were declared as int16_t properties and floating point attributes were declared as float properties in the generated interface: @interface TeamStats:NSManagedObject @property (nonatomic) int16_t pointsScored; @property (nonatomic) float winPercentage;