NSManagedObject class method error

  • + (Foo *)fooWithDefaultContext
    {
    return [NSEntityDescription insertNewObjectForEntityForName:@"Foo"
                                                    inManagedObjectContext:[[NSApp delegate] managedObjectContext]];
    }

    Throws:

    *** NSRunLoop ignoring exception '+entityForName: could not locate an
    NSManagedObjectModel'

    Why doesn't this work?

    Thanks.
  • On Oct 8, 2007, at 8:40 AM, ad veloper wrote:

    > *** NSRunLoop ignoring exception '+entityForName: could not locate an
    > NSManagedObjectModel'
    >
    > Why doesn't this work?
    >
    Because the managed object context couldn't find a managed object model.

    mmalc
  • On Oct 8, 2007, at 8:40 AM, ad veloper wrote:

    > + (Foo *)fooWithDefaultContext
    > {
    > return [NSEntityDescription insertNewObjectForEntityForName:@"Foo"
    > inManagedObjectContext:[[NSApp delegate]
    > managedObjectContext]];
    > }

    Are you sure that at the time this method is invoked, [NSApp delegate]
    returns a fully-configured delegate, and that delegate can return its
    managed object context?

    If you're invoking this before your main nib file is loaded, and
    that's where your application's delegate is configured, that would
    explain what you're seeing.

      -- Chris
  • mmalc wrote:
    > Because the managed object context couldn't find a managed object model.

    :) - Yes, sorry. I assume too much. My reporting of the error was
    based upon my assumption that everything was in place as per Chris's
    reply (below), due to the way the App is configured, but you couldn't
    guess that!

    Anyhow. Turns out that the delegate is not set, as I previously
    thought it was, which means I broke it somehow, because inserting the
    entity by passing the MOC as an argument solved the problem. Chris's
    was by far the obvious thing to check first, as mine was a bit
    longwinded.

    >
    > Are you sure that at the time this method is invoked, [NSApp delegate]
    > returns a fully-configured delegate, and that delegate can return its
    > managed object context?
    >
    > If you're invoking this before your main nib file is loaded, and
    > that's where your application's delegate is configured, that would
    > explain what you're seeing.
    >
    > -- Chris
    >
    >

    Thanks.
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today