nsmanagedobject

NSManagedObjectModel initWithContentsOfURL returns nil eventhough the modelURL is valid

喜你入骨 提交于 2019-11-30 11:03:14
my NSManagedObjectModel is returning nil eventhough the path is correct. NSString *modelKey = [NSString stringWithFormat:@"/%@/Model", name]; NSString *modelPath = [((Configuration *)[Configuration shared]) stringEntry:modelKey]; NSURL *modelURL = nil; if ( ! [modelPath contains:@"://"] ) { modelPath = PathForBundleResource( modelPath ); modelURL = [NSURL fileURLWithPath:modelPath]; } NSManagedObjectModel *m = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; NSString *PathForBundleResource(NSString *relativePath) NSString* resourcePath = [[NSBundle mainBundle] resourcePath];

Core Data: Could not cast value of type 'MyType_MyType_2' to MyType

≡放荡痞女 提交于 2019-11-30 10:53:43
I have an Objective-C model class MyType. This class is used in Swift code: NSEntityDescription.insertNewObjectForEntityForName("MyType", inManagedObjectContext: context) as! MyType The as! cast results in the error message Core Data: Could not cast value of type 'MyType_MyType_2' (0x7be99a30) to MyType (0xf33db74). If I cast it as NSManagedObject it works. When I print the result, I can nevertheless see, that it is an actual instance of MyType: <MyType: 0x7ae06d50> (entity: MyType; id: 0x7aeba6d0 <x-coredata:///MyType/t957F2860-85F8-46E0-B6D6-4D1DF6C4EC613> ; data: { ...the fields... }) What

Why might releasing a managed object crash in -[_PFManagedObjectReferenceQueue _queueForDealloc:]?

笑着哭i 提交于 2019-11-30 09:35:17
I am occasionally seeing crashes with a stack trace like this: 0 libobjc.A.dylib 0x97dc0edb objc_msgSend + 27 1 com.apple.CoreData 0x97edcdc2 -[_PFManagedObjectReferenceQueue _queueForDealloc:] + 162 2 com.apple.CoreData 0x97edccbe -[NSManagedObject release] + 94 3 com.apple.CoreFoundation 0x9318ef38 CFRelease + 152 4 com.apple.CoreFoundation 0x931a7460 __CFBasicHashStandardCallback + 384 5 com.apple.CoreFoundation 0x931a706e __CFBasicHashDrain + 478 6 com.apple.CoreFoundation 0x9318f101 _CFRelease + 353 7 com.apple.CoreFoundation 0x931bbc6d _CFAutoreleasePoolPop + 253 8 com.apple.Foundation

How to convert NSManagedObject to NSDictionary

橙三吉。 提交于 2019-11-30 09:22:48
I am trying to convert NSManagedObject to NSDictionary this is what I tried: var keys:NSArray = order?.entity.attributesByName.keys var dict:NSDictionary = order?.dictionaryWithValuesForKeys(keys) But I get error: LazyForwardCollection<MapCollectionView<Dictionary<NSObject, AnyObject>, NSObject>>? is not convertible to NSArray. What am I doing wrong here? The keys property of a dictionary returns a LazyForwardCollection which has to be converted to a real array. Another problem is that order is apparently an optional, so it needs to be unwrapped, e.g. with optional binding. if let theOrder =

Create an NSManagedObject Without Saving? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-11-30 05:14:34
Possible Duplicate: Store But Don't Save NSManagedObject to CoreData? I need to make an NSManagedObject without saving it, how can I do this? The reason I want to do this is the app has a setup in which the user enters their details, however I only want to save the object if they complete the setup (they have the option to cancel, in which case the object needs to be discarded without being saved, which is why I don't want to insert it straight away). I have tried insetting one without a context but the app crashes. I have tried the following: GuestInfo *guest; guest = (GuestInfo *)

How to handle cleanup of external data when deleting *unsaved* Core Data objects?

半世苍凉 提交于 2019-11-30 04:36:09
问题 In a managed object i have stored a path to an image file in the application's container. When the managed object get’s deleted, the image file should be moved to trash. This should be done as late as possible, so that i can provide undo functionality for as long as possible. I was following the answers of this question: How to handle cleanup of external data when deleting Core Data objects, and was overriding -didSave in my managed object subclass to trash the files. Turns out, this works

How to make a designated initializer for NSManagedObject subclass in Swift?

旧城冷巷雨未停 提交于 2019-11-30 02:54:05
class Alternative: NSManagedObject { @NSManaged var text: String @NSManaged var isCorrect: Bool @NSManaged var image: NSData } convenience init(text: String, isCorrect: Bool, entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext!) { let alternative = Alternative(entity: entity, insertIntoManagedObjectContext: context) as Alternative alternative.text = text alternative.isCorrect = isCorrect return alternative } I want to make a method that lets me initialize new objects with this call: let newAlternative = Alternative("third platform", True,

CoreData error driving me crazy… CoreData: Serious application error. An exception caught from delegate of NSFetchedResultsController

做~自己de王妃 提交于 2019-11-30 00:38:14
My application has two tab bars... Each takes the user to a tableviewcontroller that presents him with a list of items. The first view lets the user record entries in the database. The other tab/view reads from the database and presents those items to the user as well, however, no updates are made to the coreData/persistant store from this second view. When I add a new item via the first viewcontroller, it shows up perfectly in the view. However, as soon as I tap on the other tab bar to see the new item appear in that viewcontroller, I get the error listed below, and the newly added item does

core data - the primary key id of a row in the database

情到浓时终转凉″ 提交于 2019-11-29 19:12:40
Suppose I have a list of books stored in Core Data. I want to search for a book by it's primary key ID. I know the sqlite file created by Core Data has an ID column in each table, but this doesn't seem to be exposed to me in anyway. Does anyone have any recommendations? Thanks! Barry Wark -[NSManagedObject objectID] is the unique ID for an object instance in Core Data. It can be serialized via -[NSManagedObjectID URIRepresentation] . You can retrieve the objectID from a persistent store coordinator with -[NSPersistentStoreCoordinator managedObjectIDForURIRepresentation:] and then get the

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

倖福魔咒の 提交于 2019-11-29 18:47:21
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 there a convenient (perhaps, KVO-based) was I can observe changes in a context that are limited to a