nsmanagedobject

'filenames are used to distinguish private declarations of the same name' error

半腔热情 提交于 2019-11-28 04:39:30
I am getting this error on generating an NSManagedObject in Xcode 8.1 in Swift. :0: error: filename "DemoOne+CoreDataClass.swift" used twice: '/Users/Swasidhant/Desktop/demo again/DemoOne+CoreDataClass.swift' and '/Users/Swasidhant/Library/Developer/Xcode/DerivedData/demo_again-hiinrbwwbmyfbrbctsfdzvudkkuy/Build/Intermediates/demo again.build/Debug-iphonesimulator/demo again.build/DerivedSources/CoreDataGenerated/Model/DemoOne+CoreDataClass.swift' :0: note: filenames are used to distinguish private declarations with the same name :0: error: filename "DemoOne+CoreDataProperties.swift" used

What is common case for @dynamic usage?

 ̄綄美尐妖づ 提交于 2019-11-28 04:36:03
问题 There is previous post about difference of @synthesize and @dynamic. I wanna to know more about dynamic from the perspective of how to use @dynamic usually. Usually we use @dynamic together with NSManagedObject // Movie.h @interface Movie : NSManagedObject { } @property (retain) NSString* title; @end // Movie.m @implementation Movie @dynamic title; @end Actually there are no generated getter/setter during compiler time according to understanding of @dynamic, so it is necessary to implement

Swift CoreData: error: Failed to call designated initializer on NSManagedObject class 'NSManagedObject'

随声附和 提交于 2019-11-28 04:23:38
问题 I'm using core data to save a category in vc1 and want to add list properties to a list in vc2. My data model is one category to many list properties. I'm adding the category like this in vc1: func createNewCategory() { var category: NSManagedObject! = NSEntityDescription.insertNewObjectForEntityForName("Category", inManagedObjectContext: self.context) as NSManagedObject category.setValue(self.categoryTextField.text, forKey: "name") var error: NSError? = nil self.context.save(&error) }

Setting an NSManagedObject relationship in Swift

情到浓时终转凉″ 提交于 2019-11-28 04:21:31
How does one add an object to a relationship property in an NSManagedObject subclass in Swift? In Objective-C, when you generate an NSManagedObject subclass in Xcode from the data model, there's an automatically generated class extension which contains declarations like: @interface MyManagedObject (CoreDataGeneratedAccessors) - (void)addMySubObject: (MyRelationshipObject *)value; - (void)addMySubObjects: (NSSet *)values; @end However Xcode currently lacks this class generation capability for Swift classes. If I try and call equivalent methods directly on the Swift object: myObject.addSubObject

Is it possible to have multiple core data “databases” on one iOS app?

别来无恙 提交于 2019-11-28 02:15:01
问题 I'm wanting to write a "management" game that utilizes Core data heavily. The game requires a pre-set, pre-defined dataset that cannot be changed by the user/system; it is used to seed the game with data and is meant to be read-only. The best example I can give is a football management game, but it could be anything. In some football management sims they give you scenarios and pre-set datasets. As the user proceeds through the game they can save/load their progress which is saved to the core

Setting an NSManagedObject relationship in Swift

北慕城南 提交于 2019-11-27 19:15:48
问题 How does one add an object to a relationship property in an NSManagedObject subclass in Swift? In Objective-C, when you generate an NSManagedObject subclass in Xcode from the data model, there's an automatically generated class extension which contains declarations like: @interface MyManagedObject (CoreDataGeneratedAccessors) - (void)addMySubObject: (MyRelationshipObject *)value; - (void)addMySubObjects: (NSSet *)values; @end However Xcode currently lacks this class generation capability for

Core-Data willSave: method

我怕爱的太早我们不能终老 提交于 2019-11-27 18:34:38
I have an attribute modificationDate in my Entity A. I want to set its value whenever NSManagedObject is saved. However, if i try to do that in NSManagedObject willSave: method, i get an error: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to process pending changes before save. The context is still dirty after 100 attempts. Typically this recursive dirtying is caused by a bad validation method, -willSave, or notification handler.' *** So, i'm wondering, what's the best way to set the value of modificationDate ? From the NSManagedObject docs

Is there a way to instantiate a NSManagedObject without inserting it?

独自空忆成欢 提交于 2019-11-27 17:06:28
I have a user interface to insert a Transaction. once the user clicks on a plus he gets the screen and i want to instantiate my Core Data NSManagedObject entity let the user work on it. Then when the user clicks on the Save button i will call the save function. so down to code: transaction = (Transaction *)[NSEntityDescription insertNewObjectForEntityForName:@"Transaction" inManagedObjectContext:self.managedObjectContext]; //even if i dont call save: its going to show up on my table [self.managedObjectContext save:&error] P.S i am using an NSFetchedResultsController on that table and I see

Adding relationships in NSManagedObjectModel to programmatically created NSEntityDescription

ぐ巨炮叔叔 提交于 2019-11-27 16:28:32
问题 When you write a static library which uses CoreData there's a big mess including a normal .xdatamodeld file into the project because you simply cannot just link its compiled version (.momd) into your binary, so it's better to create the whole NSManagedObjectModel in the code like this: NSAttributeDescription *dateAttribute = NSAttributeDescription.new; dateAttribute.name = @"timestamp"; dateAttribute.attributeType = NSDoubleAttributeType; dateAttribute.optional = NO; dateAttribute.indexed =

Why doesn't NSManagedObject instances hold a strong reference to their NSManagedObjectContext?

試著忘記壹切 提交于 2019-11-27 16:28:08
问题 As pointed out in another question on SO (and the Apple docs), NSManagedObject instances do not hold a strong reference to the NSManagedObjectContext from which they originated. On first blush, this seems like a strange decision, since NSManagedObject instances are nearly useless without their context , since it leads to confusing bugs such as faults not firing when they should. Can anyone provide some background on why this is the case? Would it be dangerous to implement an NSManagedObject