Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS error when using Core Data when changing attribute value
    primarykey
    data
    text
    <p>Im pretty new to Core Data programming and Cocoa in general, so no wonder I'm having troubles :)</p> <p>So here is my managedObjectModel method:</p> <pre><code>- (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"Model" ofType:@"momd"]; NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; NSAssert(modelURL != nil,@"modelURL == nil"); managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return managedObjectModel; } </code></pre> <p>Here is the part of the code that crashes:</p> <pre><code>NSManagedObjectModel *mom = [self managedObjectModel]; managedObjectModel = mom; if (applicationLogDirectory() == nil) { NSLog(@"Could not find application logs directory\nExiting..."); exit(1); } NSManagedObjectContext *moc = [self managedObjectContext]; NSProcessInfo *processInfo = [NSProcessInfo processInfo]; NSEntityDescription *newShotEntity = [[mom entitiesByName] objectForKey:@"Entity"]; Entity *shEnt = [[Entity alloc] initWithEntity:newShotEntity insertIntoManagedObjectContext:moc]; shEnt.pid = [processInfo processIdentifier]; // EXC_BAD_ACCESS (code=1, address=0x28ae) here !!! NSError *error; if (![moc save: &amp;error]) { NSLog(@"Error while saving\n%@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error"); exit(1); } </code></pre> <p>Im really confused why I'm having this error, since when I hardcoded the Data Model instead of using .xcdatamodeld file it was working just fine! </p> <p>Any kind of help is really appreciated!</p> <p>EDIT 1: since I'm having all those questions asked I want to make everything clear, sorry for not providing all this before.</p> <pre><code> // Entity.h #import &lt;CoreData/CoreData.h&gt; @interface Entity : NSManagedObject @property (strong) NSDate *date; @property (assign) NSInteger pid; @end //Entity.m #import "Entity.h" @interface Entity () @property (strong) NSDate *primitiveDate; @end @implementation Entity @dynamic date,primitiveDate,pid; - (void) awakeFromInsert { [super awakeFromInsert]; self.primitiveDate = [NSDate date]; } - (void)setNilValueForKey:(NSString *)key { if ([key isEqualToString:@"pid"]) { self.pid = 0; } else { [super setNilValueForKey:key]; } } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload