nsmanagedobject

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

无人久伴 提交于 2020-01-19 06:53:08
问题 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

Creating a Subclass of a NSManagedObject

梦想的初衷 提交于 2020-01-16 05:36:06
问题 I have a subclassed NSManagedObject class: @interface MapStateDB : NSManagedObject @end Now I want to make a subclass of MapStateDB class: .h @interface MapState : MapStateDB @property (weak, nonatomic) id <MapStateDelegate> delegate; @end .m @implementation MapState @synthesize delegate = _delegate; @end Except when I try to create a MapState object, it fails: MapState *mapState = [MapState MR_createEntityInContext:context]; DLog(@"mapState: %@", mapState); output: DEBUG | -

delete core data managed object with Swift 3

99封情书 提交于 2020-01-07 02:58:27
问题 Swift 3 has migrated my code and changed: context.deleteObject(myManagedObject) to context.delete(myManagedObject) this is compiling fine (XCode 8b3) but at runtime complaining that the context does not have a function/selector delete(managedObject) Here is the runtime error: [NSManagedObjectContext delete:]: unrecognized selector sent to instance My code is very basic: func delete() { let appDel: AppDelegate = UIApplication.shared().delegate as! AppDelegate if let context:

swift 1.2 override prepareForDeletion in NSManagedObject extension

孤者浪人 提交于 2020-01-06 15:14:59
问题 Overriding the function prepareForDeletion fails in swift 1.2 // Playground - noun: a place where people can play import UIKit import CoreData extension NSManagedObject { @objc func prepareForDeletion() { println("deleting object") } } Error: method 'prepareForDeletion()' with Objective-C selector 'prepareForDeletion' conflicts with previous declaration with the same Objective-C selector @objc func prepareForDeletion() { ^ CoreData.NSManagedObject:31:14: note: 'prepareForDeletion' previously

Relationships of a child entity of ManagedObject gives wrong object

て烟熏妆下的殇ゞ 提交于 2020-01-06 12:52:08
问题 To reduce redundant data I have made a parent entity of User. Both patient and Midwife are children of User. The only additional data is that a Midwife has a set of patients and a Patient can have a set of midwifes. When I am populating the managed objects to core data it shows that their relationships to the correct objects. The problem is, when I try to retrieve the object using the User class the relationship of the ManagedObject is pointing to the wrong object (it actually points to the

iOS: Two Entities - Fetch, Merge, and Sort

会有一股神秘感。 提交于 2020-01-06 02:26:27
问题 I need to perform a fetch from two different entities, merge them, and then sort them based on a field that both entities have: 'lastModifiedDate'. lastModifiedDate is NSDate NSFetchRequest *fetchRequest1 = [[NSFetchRequest alloc] init]; NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] init]; NSEntityDescription *entity1 = [NSEntityDescription entityForName:@"Entity1" inManagedObjectContext:self.managedObjectContext]; [fetchRequest1 setEntity:entity1]; NSEntityDescription *entity2 =

Why entries are not deleted until app is restarted or I execute my NSBatchDeleteRequest twice?

风流意气都作罢 提交于 2020-01-03 02:19:36
问题 I'm reading Delete/Reset all entries in Core Data?. If I follow the steps below, I get an unexpected result: Call the code below Then query an entity in the simulator, I will get an entity back!!! If I call clearCoreDataStore again (or do a restart), only then the value won't be retrieved from core-data What am I missing? func clearCoreDataStore() { let entities = dataManager.persistentContainer.managedObjectModel.entities for entity in entities { let fetchRequest = NSFetchRequest

NSManagedObjects with Categories

北慕城南 提交于 2020-01-02 09:59:12
问题 I believe it is a common practice to put custom code for a NSManagedObject in a category of the subclass since Xcode will overrite your generated subclass when the model is edited. I just wanted to confirm this. I have seen examples where people say it is bad to combine categories with methods that are already implemented in the class hierarchy. I'm not sure if this is just for the cases when the class that has the actual category has the method already implemented or in all cases. 回答1: The

How to set an initial value for @NSManaged property PFObject Subclass?

懵懂的女人 提交于 2020-01-02 05:42:25
问题 I have a subclass of PFObject called Attendee . In this class, there is a instance variable I have called isFavorite . Below is its class definition: @NSManaged var isFavorite: Bool This is an instance var that is local to the device and I never sync it up to the server. In addition, I never explicitly instantiate the Attendee class, but rather create it by typecasting from PFObject . I would like to set the above var to have an initial value of false . How would I achieve this? 回答1: var

Core-Data: NSLog output Does Not Show “Fields”

霸气de小男生 提交于 2020-01-02 04:31:08
问题 I don't understand the output of NSLog for the array returned by a NSFetchRequest. I'm reading my database and placing the contents in an array, looping through the array and then outputting the contents with NSLog. I don't quite understand the output in the log file. Code below: -(void)createXMLFeed{ //Fetch details from the database. NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tabrss" inManagedObjectContext