nsmanagedobject

Saving Single CoreData Entity (Not the Whole Context) While Keeping NSFetchedResultController Functionality

不想你离开。 提交于 2019-12-21 04:06:43
问题 Phew, sorry for the long title. I have a single Managed Object Context where I am storing songs derived from two different locations. I get some of the songs from the persistent storage on the phone (using Core Data), and I pull some of the songs from an online database. Both of the songs are of the same MananagedObject subclass. I would like both of these songs to be in a single context because I would like them both to show up on a table view connected with an NSFetchedResultsController.

core data : differences between managed object and entities?

余生颓废 提交于 2019-12-21 02:38:07
问题 i would like to understand a bit more Core Data, why do we "fetch" and search for entities while the entities are "inside" managed objects? For example : NSManagedObjectContext *moc = [self managedObjectContext]; NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Employee" inManagedObjectContext:moc]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:entityDescription]; also, what does a persistent object store contain? if i

Comparing two NSManagedObjects

谁说胖子不能爱 提交于 2019-12-20 18:00:52
问题 I have some code that loops through an array of NSManagedObjects and stops when it finds a certain record that is stored in an instance variable. The only way I can manage to see if they are the same record (not an equivalent record, the specific record) is by comparing the URIRepresentations of the objectIDs. This surely cannot be the best way of doing it. I'm doing: if ([[[obj1 objectID] URIRepresentation] isEqualTo: [[_obj2 objectID] URIRepresentation]]) { NSLog(@"Match"); } The following

CoreData issue: -[NSManagedObject setValue:]: unrecognized selector sent to instance

夙愿已清 提交于 2019-12-20 11:36:35
问题 I just started with CoreData yesterday, and I'm going crazy :( I created a project that uses CoreData (ticked the box -use CoreData). Created the entities, and then created the NSManagedObject classes for all the entities (I suppose they create the 'setter' and 'getter' methods for the entities). Now, I #imported all these classes in my AppDeletegate and wrote this in my applicationDidFinishLaunching method: (Subscriptions is one of the Entities in the application) NSManagedObjectContext

NSNull handling for NSManagedObject properties values

余生颓废 提交于 2019-12-20 08:37:35
问题 I'm setting values for properties of my NSManagedObject , these values are coming from a NSDictionary properly serialized from a JSON file. My problem is, that, when some value is [NSNull null] , I can't assign directly to the property: fight.winnerID = [dict objectForKey:@"winner"]; this throws a NSInvalidArgumentException "winnerID"; desired type = NSString; given type = NSNull; value = <null>; I could easily check the value for [NSNull null] and assign nil instead: fight.winnerID = [dict

Cannot specialize non-generic type 'Set'

佐手、 提交于 2019-12-20 04:25:23
问题 This is my NSManagedObject : @objc(Order) class Order: NSManagedObject { @NSManaged var orderItems: Set<OrderItem> //error: Cannot specialize non-generic type 'Set' } Anyone know why it doesnt work? OrderItem file is created and works however for following declaration: @NSManaged var orderItem: OrderItem 回答1: Just for reference if someone should come to this question in the future for this nasty bug, since the discussion went on in the comments. Yes, the default Set type in Swift is generic,

Context does not save the changes with error 1550

倾然丶 夕夏残阳落幕 提交于 2019-12-20 02:13:51
问题 I'm trying to update an entity and save the changes. I'm getting always the following error: The operation couldn’t be completed. (Cocoa error 1550.) Method: - (BOOL) updateEvent:(EventDTO*)eventDTO{ BOOL saved = YES; [self getDataCoreContext]; if (context) { NSError *error; Event *myEvent = (Event *)[context existingObjectWithID:eventDTO.entitysID error:&error]; myEvent.name = eventDTO.name; myEvent.descrptn = eventDTO.description; myEvent.date = eventDTO.date; myEvent.locLatitude =

Store But Don't Save NSManagedObject to CoreData?

只愿长相守 提交于 2019-12-19 18:29:18
问题 I have a short setup process in my app and I create an NSManagedObject to store name and other details of an individual, however during this setup I don't want to save the object until the user presses 'Done' right at the end of the setup (just incase they cancel the setup for whatever reason). So is it possible to keep hold the object holding my info for a short time until the end of the setup process without actually saving it into CoreData? 回答1: When you are dealing with CoreData, all add

How to auto generate NSManagedObject subclasses with date attribute as Date instead of NSDate?

馋奶兔 提交于 2019-12-19 17:33:06
问题 I'm currently updating my project to Swift 3 and I'm moving all my NSDate methods and extensions to Date in order to keep the standard in the app. The problem is that I use Xcode to auto-generate my NSManagedObject subclasses and it is generating the date attributes as NSDate instead of Date. Is there a way to generate it with the date attributes as Date? EDIT Per Apple Developer Documentation: Core Data natively supports a variety of attribute types, such as string, date, and integer

NSMergeConflict for NSManagedObject with single ManagedObjectContext

爱⌒轻易说出口 提交于 2019-12-19 11:58:31
问题 I am working with coreData, I have one to many relationship between folders and files. I am using only one MOC through out my application .I am just passing it to different viewControllers , performing operations like add, edit, delete and then saving. My rootViewController uses NSfetchResultsController, I create folders using it, save and display on my table. saving I do it this way NSError *error; if (![self.managedObjectContext save:&error]) { // Replace this implementation with code to