nsmanagedobject

@property definitions with ARC: strong or retain?

陌路散爱 提交于 2019-11-26 07:27:05
问题 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: 1)

Xcode 8 generates broken NSManagedObject subclasses for iOS 10

最后都变了- 提交于 2019-11-26 07:00:08
问题 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

Delete/Reset all entries in Core Data?

蓝咒 提交于 2019-11-26 03:16:09
问题 Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank. Edit I\'m looking to do this programmatically so that a user can essentially hit a reset button. 回答1: You can still delete the file programmatically, using the NSFileManager:removeItemAtPath:: method. NSPersistentStore *store = ...; NSError *error; NSURL *storeURL = store.URL; NSPersistentStoreCoordinator *storeCoordinator = ...; [storeCoordinator

How can I create instances of managed object subclasses in a NSManagedObject Swift extension?

浪子不回头ぞ 提交于 2019-11-26 01:58:29
When creating an extension helper to NSManagedObject to create a new managed object subclass, swift provides the Self type to mimic instancetype which is great, but i can't seem to typecast from AnyObject . The below code does not compile with error 'AnyObject' is not convertible to 'Self' Help? extension NSManagedObject { class func createInContext(context:NSManagedObjectContext) -> Self { var classname = className() var object: AnyObject = NSEntityDescription.insertNewObjectForEntityForName(classname, inManagedObjectContext: context) return object } class func className() -> String { let

Unable to find specific subclass of NSManagedObject

天大地大妈咪最大 提交于 2019-11-26 00:44:13
问题 I\'m working on developing an app with Core Data. When I created an instance using: let entity = NSEntityDescription.entityForName(\"User\", inManagedObjectContext: appDelegate.managedObjectContext) let user = User(entity: entity, insertIntoManagedObjectContext: appDelegate.managedObjectContext) I got a warning in log: CoreData: warning: Unable to load class named \'User\' for entity \'User\'. Class not found, using default NSManagedObject instead. How could I fix it? And another question,