Managed Object Context arrives empty when passed via a segue in iOS 5

- by

I’ve just found that passing an NSManagedObjectContext object via a segue in iOS 5 doesn’t work: the property remains empty.

In iOS 6 on the other hand this isn’t a problem: the context arrives just like any other property would, and as logic would dictate. Here’s code from an amended Utility Template app:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showAlternate"]) {
        
        // also onpass the managed object context
        self.flipsideViewController = [[FlipsideViewController alloc]init];
        self.flipsideViewController.managedObjectContext = self.managedObjectContext;
        self.flipsideViewController = segue.destinationViewController;
        self.flipsideViewController.delegate = self;
    }
}

Trying to execute a Fetch Request on FlipsideViewController results in this error message:

+entityForName: could not locate an NSManagedObjectModel for entity name ‘YourEntity’

The fact that this is fixed (yet completely undocumented) means that Apple knew about this and made it work in iOS 6. Why this doesn’t work in iOS 5 is anyone’s guess.



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.