core-data

How to access Core Data generated Obj-C classes in test targets?

橙三吉。 提交于 2020-01-11 10:08:10
问题 I have a Core Data / Swift Cocoa application project in Xcode 6 (let's call the project Stuff ). I created a Core Data entity called Query and used Xcode to create an NSManagedObject subclass for it. At that point, Xcode 6 offered to create the bridging header for me, as expected, and created Stuff-Bridging-Header.h . Once I #import "Query.h" in the bridging header, then my model object Query is available in my app target Swift code. How do I make that Query Core Data object (backed by the

How can I solve NSInternalInconsistencyException', reason: '+entityForName: fail report

谁都会走 提交于 2020-01-11 09:43:31
问题 My code looks like that: NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; // If appropriate, configure the new managed object. [newManagedObject setValue:[NSDate date] forKey:@"date"]; // Save the context. NSError *error = nil; if (!

How can I solve NSInternalInconsistencyException', reason: '+entityForName: fail report

荒凉一梦 提交于 2020-01-11 09:43:09
问题 My code looks like that: NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; // If appropriate, configure the new managed object. [newManagedObject setValue:[NSDate date] forKey:@"date"]; // Save the context. NSError *error = nil; if (!

Setting the value of a double attribute on NSManagedObject

微笑、不失礼 提交于 2020-01-11 09:34:11
问题 I am trying to implement a maps feature on my application. However to I would like the latitude and longitude be passed into the map from an object that is stored in core data. However I am having problem setting the initial value on the object when I start my application. I have tried 2 different ways so far and each and error I receive is "Sending 'double to a parameter of incompatible type 'id'. Any help would be very appreciated. NSManagedObject *room = [NSEntityDescription

Setting the value of a double attribute on NSManagedObject

孤者浪人 提交于 2020-01-11 09:34:09
问题 I am trying to implement a maps feature on my application. However to I would like the latitude and longitude be passed into the map from an object that is stored in core data. However I am having problem setting the initial value on the object when I start my application. I have tried 2 different ways so far and each and error I receive is "Sending 'double to a parameter of incompatible type 'id'. Any help would be very appreciated. NSManagedObject *room = [NSEntityDescription

NSManagedObject's managedObjectContext property is nil

 ̄綄美尐妖づ 提交于 2020-01-11 08:56:24
问题 I'm trying to create a temporary managed object context, and after a few screens of the user putting in information, I merge that context with the main context (to ensure that there are no "incomplete" objects are inserted). This is how I create my temporary context and how I insert an object in it: if (!self.someManagedObject) { NSManagedObjectModel *model = [NSManagedObjectModel mergedModelFromBundles:@[[NSBundle mainBundle]]]; NSPersistentStoreCoordinator *storeCoordinator = [

Core Data. How to swap NSPersistentStores and inform NSFetchedResultsController?

ぃ、小莉子 提交于 2020-01-11 07:50:13
问题 I'm implementing backup and restore (via Dropbox) of a user's Core Data persisted data. For a restore I pull the files down from Dropbox and store them temporarily in the Documents directory. Then I create a new NSPersistentContainer and use it to replace the current persistent store (in the ApplicationSupport directory) before deleting the no longer needed files in the Documents directory. I'm using the MasterDetail template for now and so I have the usual time-stamped entities and the

CoreData many-to-many relationship

痞子三分冷 提交于 2020-01-11 03:41:05
问题 How to operate with many-to-many relationship in CoreData? For example: I have 2 entities - Recipes & Ingredients CoreData links them like Recipes <<-->> Ingredients. Now I need to add attribute "Count" for every Ingredient in Recipe. How can I do it? Thanks 回答1: Core Data takes care of the object graph consistency maintenance for you. So if you use a SQLite store, Core Data automatically creates the intermediate join table for you for many-to-many relationships. In your case, you should

Solution For Monitoring and Maintaining App's Size on Disc

旧时模样 提交于 2020-01-11 03:19:10
问题 I'm building an app that makes extensive use of CoreData and a lot of my models have UIImage and NSData properties (for images and videos). Since it's not a great idea to store that data directly into CoreData, I built a file manager class that writes the files into different buckets in the documents directory depends on the context in which was created and media type. My question now is how do I manage the documents directory? Is there a way to detect how much space the app has used up out

Can NSManagedObject conform to NSCoding

为君一笑 提交于 2020-01-11 02:40:47
问题 I need to transfer a single object across device. Right now I am converting my NSManagedObject to a dictionary , archiving it and sending as NSData. Upon receiving I am unarchiving it. But I would really like to transfer the NSManagedObject itself by archiving and unarchiving instead of creating an intermediate data object. @interface Test : NSManagedObject<NSCoding> @property (nonatomic, retain) NSString * title; @end @implementation Test @dynamic title; - (id)initWithCoder:(NSCoder *)coder