Nikunj Jadav
Nikunj Jadav

Reputation: 3402

Core Data Bad Access insertNewObjectForEntityForName issue

I have bad access issue in core data while insert data in database and I also used @try,@catch block but I can't find any solution for the same. I am stuck for last 3days so please help me for solve this issue or give me any suggestion.

- (BOOL) addSynchedContactsList:(int)aAppContactId :(NSString*)aDevContactId
{
    NSManagedObjectContext *context = [[PFCoreDataController sharedCoreDataController] managedObjectContext];
    BOOL success = YES;

    ContactsListSync *syncContact = (ContactsListSync *)[NSEntityDescription insertNewObjectForEntityForName:ENTITY_CONTACTSLISTSYNC inManagedObjectContext:context];

    syncContact.appContactlistId = [NSNumber numberWithInt:aAppContactId];
    syncContact.devConatctlistId = aDevContactId;

    return success;
} 

In this line,

ContactsListSync *syncContact = (ContactsListSync *)[NSEntityDescription insertNewObjectForEntityForName:ENTITY_CONTACTSLISTSYNC inManagedObjectContext:context];

OR

ContactsListSync *syncContact = (ContactsListSync *)[[NSEntityDescription insertNewObjectForEntityForName:ENTITY_CONTACTSLISTSYNC inManagedObjectContext:context] retain];

So Please give me any suggestion or any idea.

Thanks in advance for help.

Upvotes: 0

Views: 324

Answers (1)

Dean Davids
Dean Davids

Reputation: 4214

Put a break point at the first line and step through each. I would be checking for the following:

  • context is a valid context (hover over or type po context after assignment)
  • ENTITY_CONTACTSLISTSYNC resolve to a valid entity name
  • aAppContactId and aDevContactId are valid values

Check ContactListSync Entity for required fields not provided?

If it is failing at the third line, seems would be one of three things, context invalid, context on another thread, entity name incorrect. What clues do you get in the error message at exception?

Upvotes: 1

Related Questions