Error entering master data

I am working with Core Data and trying to get it to display data using a simple data model. The application crashes and gives me this error message

Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "+ entityForName: nil is not a legitimate parameter NSManagedObjectContext, which searches for the name of the object" Remind "

I'm not quite sure, but as I understand it, he says that he cannot find my object called "Remind"? However, I actually have an object called Remind.

I also set breakpoints and it stops right here: enter image description here

Any help would be greatly appreciated. Completely at a standstill.

Managed Context Code in App Delegate.m

enter image description here

+5
source share
1 answer

The problem is that your accessory and your ivar have the same name. Where the convention from Ibar comes from. Here you do not use accessor to access the property, you use direct backup directly, so it is never initialized. Instead, make sure you always use your access methods and you will not have a problem. So, rewrite the insult method (and any others that use the property managedContextObject, with something like the following:

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated]; // it good practice to call the super methods, even if you're fairly certain they do nothing

  // Get a reference to the managed object context *through* the accessor
  NSManagedObjectContext* context = [self managedObjectContext];

  // From now on, we only use this reference in this method
  NSFetchRequest = [[NSFetchRequest alloc] init];
  NSEntityDescription* entity = [NSEntityDescription entityForName:@"Remind" inManagedObjectContext:context]; // <- use the local reference we got through the accessor
  [request setEntity:entity];
  NSError* error = nil;
  NSArray* array = [context executeFetchRequest:request error:&error];
  if( !array ) {
    // Do something with the error
    NSLog(@"Error Fetching: %@", error);
  }
  [self setDesitnationsArray:[array mutableCopy]];
  [destinationsTableView reloadData];
}

, ivars , , , , _managedObjectContext _privateContext, -, , . Objective-C , , , self, , self.managedObjectContext. , , , , , , ( ).

+1

All Articles