nsmanagedobject

Context does not save the changes with error 1550

喜夏-厌秋 提交于 2019-12-01 20:59:00
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 = [eventDTO getLatidude]; myEvent.locLongitude = [eventDTO getLongitude]; myEvent.numberOfInvited= [NSNumber

Get class name in convenience init Swift 3

可紊 提交于 2019-12-01 18:43:06
问题 I'm trying to implement my own version of convenience init(context moc: NSManagedObjectContext) , the new convenience initialiser on NSManagedObject in iOS 10. Reason being I need to make it compatible with iOS 9. I've come up with this: convenience init(managedObjectContext moc: NSManagedObjectContext) { let name = "\(self)".components(separatedBy: ".").first ?? "" guard let entityDescription = NSEntityDescription.entity(forEntityName: name, in: moc) else { fatalError("Unable to create

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

烂漫一生 提交于 2019-12-01 17:27:08
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 (represented as instances of NSString, NSDate and NSNumber respectively). So I think it's not possible =/ It

Abstract entities and inheritance in Core Data

落花浮王杯 提交于 2019-12-01 15:03:25
I have a data model for Formula 1 races with 3 entities: RacingActor: Abstract entity Pilot: inherits from RacingActor Team: inherits from RacingActor If I generate NSManagedObject subclasses to represent these entities, the code generated doesn't represent at all this design: Everything inherits from NSManagedObject Nothing prevents me from instantiating RacingActor The team property in Pilot is of type NSManagedObject instead of Team Is this the expected behaviour? Am I supposed to fix the code generated by Xcode? Am I missing something? BTW, I'm using Xcode 4.3.3 fabrice truillot de

NSMergeConflict for NSManagedObject with single ManagedObjectContext

柔情痞子 提交于 2019-12-01 14:12:17
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 handle the error appropriately. // abort() causes the application to generate a crash log and terminate.

Abstract entities and inheritance in Core Data

时间秒杀一切 提交于 2019-12-01 13:54:22
问题 I have a data model for Formula 1 races with 3 entities: RacingActor: Abstract entity Pilot: inherits from RacingActor Team: inherits from RacingActor If I generate NSManagedObject subclasses to represent these entities, the code generated doesn't represent at all this design: Everything inherits from NSManagedObject Nothing prevents me from instantiating RacingActor The team property in Pilot is of type NSManagedObject instead of Team Is this the expected behaviour? Am I supposed to fix the

iOS - “Too Many Contexts” error?

*爱你&永不变心* 提交于 2019-12-01 12:10:28
问题 My App (under development, iOS 5.1) occasionally crashes with the following message: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Too many contexts. No space in contextList.' Googling this message returns zero results. I'm using a single NSManagedObjectContext taken from the AppDelegate singleton, simple and straightforward, no tricks. Any ideas? 回答1: You've probably got some object recursing into itself during construction, probably in alloc or init

How to count unique dates of CoreData objects?

穿精又带淫゛_ 提交于 2019-12-01 11:17:03
I need a proper way to count how many unique days there are in CoreData objects with a property of type NSDate. For example, I have the following: <Object>.date = "2014-05-15 21:29:12 +0000"; <Object>.date = "2014-05-15 21:49:34 +0000"; <Object>.date = "2014-05-16 13:29:23 +0000"; <Object>.date = "2014-05-16 20:49:50 +0000"; <Object>.date = "2014-05-16 22:01:53 +0000"; <Object>.date = "2014-05-20 03:32:12 +0000"; <Object>.date = "2014-05-20 12:45:23 +0000"; <Object>.date = "2014-05-20 14:15:50 +0000"; <Object>.date = "2014-05-20 20:20:05 +0000"; In this case, the result must be 3 because there

Core Data inheritance vs no inheritance

感情迁移 提交于 2019-12-01 09:06:21
问题 i'm having some issues with core data, so i hope that someone will be able to help me :) First problem, i have a data model that looks like this : Entity P (A) <----> Entity R / | \ / /\ \ / / | \ \ C D E F G All my entities inherit from the same entity "P" because they need a common attribute and a common relationship ("A" and "R") The problem i am getting is that core data uses generates only one sqlite table for all the entities when you use inheritance. In my case it means that my

How to count unique dates of CoreData objects?

亡梦爱人 提交于 2019-12-01 08:22:50
问题 I need a proper way to count how many unique days there are in CoreData objects with a property of type NSDate. For example, I have the following: <Object>.date = "2014-05-15 21:29:12 +0000"; <Object>.date = "2014-05-15 21:49:34 +0000"; <Object>.date = "2014-05-16 13:29:23 +0000"; <Object>.date = "2014-05-16 20:49:50 +0000"; <Object>.date = "2014-05-16 22:01:53 +0000"; <Object>.date = "2014-05-20 03:32:12 +0000"; <Object>.date = "2014-05-20 12:45:23 +0000"; <Object>.date = "2014-05-20 14:15