nsmanagedobject

How can I track/observe all changes within a subgraph?

柔情痞子 提交于 2019-11-28 13:41:41
问题 I have a NSManagedObjectContext in which I have a number of subclasses of NSManagedObjects such that some are containers for others. What I'd like to do is watch a top-level object to be notified of any changes to any of its properties, associations, or the properties/associations of any of the objects it contains. Using the context's 'hasChanges' doesn't give me enough granularity. The objects 'isUpdated' method only applies to the given object (and not anything in its associations). Is

Can someone explain this @synthesize syntax?

偶尔善良 提交于 2019-11-28 12:59:37
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 (nonatomic, retain) NSFetchedResultsController *fetchedResultsController; Does this mean that they are both

Passing generic Class as argument to function in swift

徘徊边缘 提交于 2019-11-28 11:38:46
问题 Below is my method in which there is fetch I make on a Managed object Class Appointment. I need to use same function for other similar managed object Classes. How do I pass different "Class" as parameter every time as I need. And also use it to fetch as I have currently "Appointment" Class. I might need to use Generics may be. Dont know how though. func getAppointmentArray(aPredicate : String , aModel : Any) -> [Any] { var apptArr = [Any]() let fetchRequest = NSFetchRequest<Appointment>

Using Swift protocols with generics

纵饮孤独 提交于 2019-11-28 08:50:57
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 protocol CoreDataModel , and CoreDataModel defines an optional class method called entityName . However,

Cross-model relationships in NSManagedObjectModel from merged models?

坚强是说给别人听的谎言 提交于 2019-11-28 08:40:02
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 there any way to define these relationships either in the data modeler or programatically so that they

What are the functional differences between Coredata's CodeGen 'manual/none + create NSManagedObject subclass' vs. 'category/extension'

自闭症网瘾萝莉.ら 提交于 2019-11-28 07:42:51
问题 I've read Subclassing NSManagedObject with swift 3 and Xcode 8 beta and read this great tutorial. Still have questions on some points. The similarities are: I can customize both classes however I like. I can add new attributes or remove or rename attributes. ie for category/extension it will get updated upon a new build (in the derived data), and in case of manual/none it will leave the class file intact and update the extension in the file navigation ie I won't end up with a duplicate file.

Subclassing NSManagedObject with swift 3 and Xcode 8 beta

为君一笑 提交于 2019-11-28 06:53:59
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 allowed at the top level. Use of unresolved identifier '___COREDATA_DATAMODEL_MANAGEDOBJECTCLASSES

invalid redeclaration in auto code generate NSManagedObject Subclass Swift 3

瘦欲@ 提交于 2019-11-28 06:09:23
Using Version 8.1 of Xcode. Create an entity named "MapRegionObject" in .xcdatamodeld file. Using auto code generator, click Editor on the navigation bar -> create NSManagedOject Subclass... Got two files : MapRegionObject+CoreDataClass.swift and MapRegionObject+CoreDataProperties Errors in two files showing in the screenshot: MapRegionObject+CoreDataClass.swift MapRegionObject+CoreDataProperties Please help me fix this bugs, thank you so much! Kamillpg In Xcode 8.1, before using the auto code generator, you must select the entity in your data model: Then go to the Data Model Inspector tab:

Generating Swift models from Core Data entities

て烟熏妆下的殇ゞ 提交于 2019-11-28 05:39:55
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 from my Core Data's entities, Xcode creates Objective-C models. Is there a way to generate Swift model

Custom initializer for an NSManagedObject

情到浓时终转凉″ 提交于 2019-11-28 05:36:10
问题 According to the docs: You should not override init. You are discouraged from overriding initWithEntity:insertIntoManagedObjectContext: and you should instead use awakeFromInsert or awakeFromFetch. This is fine if all I want to do is set some attribute to the current date or similar, but what if I want to send in another object and set attributes based on its information? For example, in an NSManagedObject subclass called 'Item', I want an initFromOtherThing:(Thing *)thing, in which the item