Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:17:04+00:00 2026-06-13T20:17:04+00:00

Im pretty new to Core Data programming and Cocoa in general, so no wonder

  • 0

Im pretty new to Core Data programming and Cocoa in general, so no wonder I’m having troubles 🙂

So here is my managedObjectModel method:

- (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;
}

Here is the part of the code that crashes:

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: &error])
{
   NSLog(@"Error while saving\n%@",
        ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
        exit(1);
}

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!

Any kind of help is really appreciated!

EDIT 1: since I’m having all those questions asked I want to make everything clear, sorry for not providing all this before.

    // Entity.h

    #import <CoreData/CoreData.h>

    @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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:17:05+00:00Added an answer on June 13, 2026 at 8:17 pm

    Using scalar values in core data is a bit more work than using the recommended NSNumber. This is described in detail in this section of the Core Data Programming Guide.

    I strongly recommend you switch this property to NSNumber. Your assignment statement would then be:

    shEnt.pid = [NSNumber numberWithInt:[processInfo processIdentifier]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Core Data, and I'm trying to wrap my head around
Im building an app that will use a Core Data model. I pretty new
Ok so I am pretty new to Core Data, and I am now starting
I'm pretty new to Core Data and managed to get the NSTableView to show
What I'm doing: I'm pretty new to doing data migrations with Core Data, but
Pretty new to Perl so there may be a very obvious solution here. I'm
I have a core data app set up, and everything is working pretty well.
I'm fairly new to the more complex parts of Core Data. My application has
I am having usues with performance when inserting 2000 records in my Core Data
I'm new to Core Data and I'm working on my first personal iOS app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.