> NSManagedObject *hostObj = [NSEntityDescription
> insertNewObjectForEntityForName:@"Host" inManagedObjectContext:[[NSApp
> delegate] managedObjectContext]];
>

Ahhh... there's what I was missing:  the [NSApp delegate] part of
declaring a new entity.  I'm not at my Mac right now, but I'll give
that a try tonight.

> then set the values on that object with:
>
> [hostObj setValue: hostString forKey:@"hostStringKey"];
> etc...

Yep, that's what I've been doing, but I've been chasing the
ManagedObjectContext around.  I'm thinking that the example above will
fix that.

>
> Second, your +(id)addHostFromPanel: method is a class method yet
> you're asking for [self managedObjectContext], which is an instance
> method.  Basically, you don't have a properly initialized managed
> object at the time you asked for the context it's in.

Yea, I figured that wasn't right.

>
> If you're set on sticking with the class method, you could do
> something like the following:
>
> // Written in TextEdit, forgive the formatting
> +(id)addHostFromPanel:(NSString *)hostPanel name:(NSString *)hostName
> ipAddress:(NSString *)ipAddress group:(NSString *)group
> inManagedObjectContext:(NSManangedObjectContext *)objContext
> {
>        self = [super insertNewObjectForEntityForName:@"Host"
> inManagedObjectContext:objContext];
>        if( self != nil )
>        {
>                [self setValue:hostName forKey:@"hostNameKey"];
>                etc...
>        }
>
>        return( self );
> }
>
>
> I'm not much of a CoreData ninja but I hope that helps.
>
> Jim
>

Awesome, thanks!  I think this will help out a lot.

Jon
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to