nsmanagedobject

Using Swift protocols with generics

只谈情不闲聊 提交于 2019-11-27 02:28:23
问题 I have a simple example that seems like it should work: import CoreData @objc protocol CoreDataModel { @optional class func entityName() -> String } class AbstractModel: NSManagedObject, CoreDataModel { class func create<T : CoreDataModel>(context:NSManagedObjectContext) -> T { var name = T.entityName?() var object = NSEntityDescription.insertNewObjectForEntityForName(name, inManagedObjectContext: context) as T return object } } So we have a class called AbstractModel which conforms to the

Cross-model relationships in NSManagedObjectModel from merged models?

删除回忆录丶 提交于 2019-11-27 02:20:16
问题 Is it possible to model relationships between entities that are defined in separate NSManagedObjectModels if the entities are always used within an NSManagedObjectModel that is created by merging the relevant models? For example, say model 1 defines an entity Foo with relationship (one-to-one) toBar and that model 2 defines an entity Bar with a relationship (one-to-one) toFoo . I will build a CoreData stack using -[NSManagedObjectModel mergedModelFromModels] , merging model 1 and model 2. Is

Removing a specific entry/row from Core-Data

天大地大妈咪最大 提交于 2019-11-27 01:06:12
问题 I'm using core data in my app, and i'm confused when it comes to removing certain rows or entries from the core data storage. I insert some products in to the storage like so: NSManagedObject *Product = [NSEntityDescription insertNewObjectForEntityForName:@"Product" inManagedObjectContext:context]; [Product setValue:[NSNumber numberWithFloat:id] forKey:@"pid"]; [Product setValue:[NSNumber numberWithFloat:quantity] forKey:@"pquantity"]; This works fine for insertion. However, later in the app,

Generating Swift models from Core Data entities

╄→гoц情女王★ 提交于 2019-11-27 00:59:50
问题 Update for Xcode 8: In Xcode 8, one needs to go to the Core Data Model Editor and Show the File Inspector. Near the bottom is an option for code generation. Select Swift. Edit : I found the solution to generate a Swift model from Core Data entity: On Xcode: Editor > Create NSManagedOjbect > Click button "Next" > Click button "Next" > Select "Swift" Langage > Click button "Create" I tried Swift langage by creating a new Swift project on Xcode 6 beta using Core Data. When I generate my models

How can I tell whether an `NSManagedObject` has been deleted?

痞子三分冷 提交于 2019-11-26 23:47:11
I have an NSManagedObject that has been deleted, and the context containing that managed object has been saved. I understand that isDeleted returns YES if Core Data will ask the persistent store to delete the object during the next save operation. However, since the save has already happened, isDeleted returns NO . What is a good way to tell whether an NSManagedObject has been deleted after its containing context has been saved? (In case you're wondering why the object referring to the deleted managed object isn't already aware of the deletion, it's because the deletion and context save was

How can I duplicate, or copy a Core Data Managed Object?

家住魔仙堡 提交于 2019-11-26 23:36:56
I have a managed object ("A") that contains various attributes and types of relationships, and its relationships also have their own attributes & relationships. What I would like to do is to "copy" or "duplicate" the entire object graph rooted at object "A", and thus creating a new object "B" that is very similar to "A". To be more specific, none of the relationships contained by "B" (or its children) should point to objects related to "A". There should be an entirely new object graph with similar relationships intact, and all objects having the same attributes, but of course different id's.

Permanent NSManagedObjectID not so permanent?

╄→гoц情女王★ 提交于 2019-11-26 20:15:39
问题 I'm having trouble dealing with object IDs in CoreData. I'm using MagicalRecord for convenience and have 3 contexts: a private queue working context, a main queue context for UI and parent to the working context, and a private queue saving context that is the parent of the main context. My goal is to create an object in the working context, save to the persistent store, save it's objectID URL to NSUserDefaults, and then be able to pull out that MO using the objectID later on. However, what I

Changing a managed object property doesn't trigger NSFetchedResultsController to update the table view

a 夏天 提交于 2019-11-26 19:53:52
I have a fetchedResultsController with a predicate, where "isOpen == YES" When calling for closeCurrentClockSet , I set that property to NO . Therefore, it should no longer appear on my tableView. For Some Reason, this is not happening. Can someone help me figure this out please? -(void)closeCurrentClockSet { NSPredicate * predicate = [NSPredicate predicateWithFormat:@"isOpen == YES"]; NSArray *fetchedObjects = [self fetchRequestForEntity:@"ClockSet" withPredicate:predicate inManagedObjectContext:[myAppDelegate managedObjectContext]]; ClockSet *currentClockSet = (ClockSet *)fetchedObjects

@property definitions with ARC: strong or retain?

巧了我就是萌 提交于 2019-11-26 19:51:53
Using Xcode 4.2 and ARC, I notice that the auto-generated code for an NSManagedObject still reads like this for properties: @property (nonatomic, retain) NSString * someString; 1) Shouldn't retain now be replace with strong or weak ? 2) Why does the auto-generated code still use retain 3) What is the correct replacement for retain in this property statement? I'm currently debugging a problem using NSFetchRequest , and I thought this might be the source of the problem. Thoughts? 1) Shouldn't retain now be replace with strong or weak? No. You cannot replace retain with weak; they are different.

Xcode 8 generates broken NSManagedObject subclasses for iOS 10

烂漫一生 提交于 2019-11-26 19:34:26
I updated my iOS app project recently to iOS 10. Now I'm trying to change the Core Data Model of my app but the new NSManagedObject subclasses which Xcode generates are broken. I also tried to fix the subclasses manual but this doesn't work. The minimum tools version for the Core Data Model is set to Xcode 7.0 and code generation language is set to Swift. This is the code which Xcode generates: import Foundation import CoreData import extension Group { @nonobjc public class func fetchRequest() -> NSFetchRequest { return NSFetchRequest(entityName: "Group"); } @NSManaged public var name: String?