nsmanagedobject

Understanding NSManagedObject

穿精又带淫゛_ 提交于 2019-12-07 18:45:10
问题 In an existing project I have tried to introduce Core Data long after the project was created, so its model is already in place. I have created the xcdatamodel and added my only class to it. That class should act as a global storage for objects in my application. The class properly implement NSManagedObject and I have verified it gets created and saved in context, also retrieved with a fetch result. The way of saving data in this class is by means of NSMutableArray. But this is just not

cast NSManagedObject to class -> Swift dynamic cast failed

送分小仙女□ 提交于 2019-12-07 15:36:10
问题 i hope you can help! I have a class called Exercise: import Foundation import CoreData class Exercise: NSManagedObject { @NSManaged var name: String } and created an Entity called Exercise with an attribute "name" of type String. Now i want to access it from a ViewController: var context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext! var exercise: NSManagedObject = NSEntityDescription.insertNewObjectForEntityForName("Exercise", inManagedObjectContext:

add additional properties to NSManagedObject with secondary .h .m files

戏子无情 提交于 2019-12-07 14:03:07
问题 I have some NSManagedObject classes created for use with CoreData I need to add some additional properties for formatting I am doing using GRMustache templates. Here is an example property: -(NSString *) PriceFormatted { NSNumberFormatter *nfm = [[[NSNumberFormatter alloc] init] autorelease]; [nfm setNumberStyle:NSNumberFormatterCurrencyStyle]; [nfm setCurrencyCode:[Helpers GetCurrencyCode]]; [nfm setNegativeFormat:@"-¤#,##0.00"]; [nfm setMaximumFractionDigits:2]; return [nfm stringFromNumber

Can't get rid of compiler warnings for primitiveValue accessors in transient property getter impls

余生长醉 提交于 2019-12-07 10:14:04
问题 I've implemented a transient property as below on one of the models in my app. It is declared in the model design as a transient property with undefined type. @property (nonatomic, readonly) NSNumberFormatter *currencyFmt; The current (warning-free) impl of this accessor is: - (NSNumberFormatter *) currencyFmt { [self willAccessValueForKey:@"currencyFmt"]; NSNumberFormatter *fmt = [self primitiveValueForKey:@"currencyFmt"]; [self didAccessValueForKey:@"currencyFmt"]; if (fmt == nil) { fmt = [

Core Data returns a different object instance for the same NSManagedObject each time I fetch it. Why is this?

旧城冷巷雨未停 提交于 2019-12-07 09:12:08
问题 I have recently noticed that if I fetch a ManagedObject of which I can verify that there is only one in the model and which is not retained anywhere in my application, every time the fetch returns the object it is a different instance (with a pointer to a different memory adress). Why is this? 回答1: If no one retains it, Core Data is free to release it. If you ask for it again, it will probably be at a different memory location. You can't count on it being the same object instance. 回答2: A

Does an NSManagedObject retain its NSManagedObjectContext?

谁都会走 提交于 2019-12-07 07:13:16
问题 NSManagedObject provides access to its NSManagedObjectContext, but does it retain it? According to "Passing Around a NSManagedObjectContext on iOS" by Marcus Zarra, "The NSManagedObject retains a reference to its NSManagedObjectContext internally and we can access it." How does Zarra know this and is he correct? I'm asking because I want to know if the NSManagedObjectContext will be dealloc 'ed in the tearDown method below. (I'm using CocoaPlant.) #import <SenTestingKit/SenTestingKit.h>

Trying to implement master-child Managed Object Context when doing mass delete in Core Data

女生的网名这么多〃 提交于 2019-12-06 15:36:53
I am working on a project where I am doing a mass delete of a number of NSManagedObjects (MO) that I retrieve from Core Data. When I iterate through this collection of MO's, I am also retrieving OTHER MO's by calling a fetch method DURING the iteration of the initial collection of MO's. If during this iteration process, an object is found from the fetch request, the MO is deleted. I realize that this is a poor design of the architecture, as these MO's should in fact be having inverse relationships with one another, and therefore via a cascade delete rule, all of these objects would easily be

Understanding NSManagedObject

和自甴很熟 提交于 2019-12-06 13:22:24
In an existing project I have tried to introduce Core Data long after the project was created, so its model is already in place. I have created the xcdatamodel and added my only class to it. That class should act as a global storage for objects in my application. The class properly implement NSManagedObject and I have verified it gets created and saved in context, also retrieved with a fetch result. The way of saving data in this class is by means of NSMutableArray. But this is just not working. Here's a fragment of this class: @interface WZMPersistentStore : NSManagedObject<NSCoding> {

Is it possible to have Core Data sort the “many” part of a To-Many relationship during a fetch request?

给你一囗甜甜゛ 提交于 2019-12-06 12:38:41
I'm using Core Data to cache a decent amount of information, and I have a To-Many relationship set up among my managed objects. Naturally I use an NSFetchRequest to fetch an array of the singular side of that relationship. However, I populate a UITableView using the the "many" side of the relationship, and I'd like it to be sorted alphabetically when I pull the data. If I'm not being clear, here's an example: "employee" and "boss" are both NSManagedObjects in a To-Many relationship - each boss has many employees, but employees only have one boss. After retrieving an array of bosses, I push a

iOS Core Data how to properly initialize entity relationships?

扶醉桌前 提交于 2019-12-06 11:48:27
I have a one to many relationship in my core data model. I need to create a new entity and save it. The entity has a one to many relationship which generated the following code: - (void)addRelationshipEvent1:(NSSet *)values; - (void)removeRelationshipEvent1:(NSSet *)values; . NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; ApplicationRecord *newManagedObject = (ApplicationRecord*)[NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext