UA-17470720-3

Jump to content


Photo
- - - - -

NSManagedObjectContext error with context called by multiple views

data-stores data-definitions models core-data

  • Please log in to reply
1 reply to this topic

#1 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 29 May 2014 - 03:31 PM

Anyone else get this error?

 

'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name ......

 

My code is using the core data Single object view model from page 49 of the STV eBook. My program has a left tab bar which uses the Single object view model to make an update User data table view and a right tab bar that uses Single object view model to create a form to upload activity data.

 

It was working with just the User screen. However, when I tried to add the upload activity form view controller it gave me

 

'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'ActivityEntity''

 

Later I changed my upload activity controller to not use core data and remove all references thereof, but now the previously working user entity which I did not change is failing with

 

'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'UserDataEntity''

 

I checked for and fixed all misspellings or bad references. Reading about this error on stackoverflow, this is typically caused by failure to call NSManagedObjectContext correctly in "prepareforsegue" and that NSManagedObjectContext should not be called in AppDelgate (though this is the default core data template).

 

Is this an internal problem of STV or something else? Has anyone else successfully fixed? I am too new to Core Data and STV to understand what is happening.

 

Note: I tried this person's solution but it did not fix.

http://sensiblecocoa...y-in-the-table/



#2 rolfenstein

rolfenstein

    Jr. Member

  • STV 4.0 Pro
  • PipPip
  • 16 posts
Reputation: 1
Good

Posted 29 May 2014 - 10:04 PM

Actually I take back what I wrote in the note. The solution from http://sensiblecocoa...-in-the-table/ 

works.

 

Essentially it needs to use

 

        myObject = [NSEntityDescription insertNewObjectForEntityForName:@"EntityName" inManagedObjectContext:context];

instead of 
                myObject = [entityStore createNewObject];

 

 

I broke my app apart and rebuilt the core data parts piece by piece and it works, so maybe had one of the tables use "createNewObject" before. Does anyone know why this is? Is there an error in STV that it needs to directly call to NSEntityDescription instead of SCCoreDataStore?







Also tagged with one or more of these keywords: data-stores, data-definitions, models, core-data

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users