Hello,

I have a problem with my app that is most likely very simple for someone with experience. I have a core data based application that I would like to be able to add objects to via a sheet that drops down when the user clicks the + button (or presses Command-N). On the sheet are two NSTextField and one NSPopUpButton, an add button and a cancel button. From my AppController class I can get the values as strings that are entered into the sheet here:
- (IBAction)endAddHostSheet:(id)sender
{
        
        NSString *hostString = [hostNameTextField stringValue];
        if ([hostString length] == 0)
        {
                return;
        }       
        NSLog(@"the host name is %@", hostString);
        
        NSString *ipAddressString = [ipAddressTextField stringValue];
        if ([ipAddressString length] == 0)
        {
                return;
        }               
        NSLog(@"the ip address  is %@", ipAddressString);
        
NSString *selectedGroupString = [groupsPopUpButton titleOfSelectedItem];
        NSLog(@"the selected Group is %@", selectedGroupString);
        
        // Do stuff to add to core data here... 
        
        
        [NSApp endSheet:addHostSheet];
        
        //Goodbye, sheet
        [addHostSheet orderOut:sender]; 
}

But my question is, how can I add these strings to core data?

My core data setup is very simple. I have three entities (one which I'm not yet using) named Host, Group, and ContactGroup. Host has attributes hostName, ipAddress, and a to-one relationship named group. Group has an attribute groupName, and a to-many relationship named hosts.
I've defined classes for the Entities, like this:

#import <Cocoa/Cocoa.h>
@class ContactGroup;
@class Group;

@interface Host : NSManagedObject {

}

@property (readwrite, retain) ContactGroup *contactGroup;
@property (readwrite, retain) Group *group;
@property (readwrite, copy) NSString *hostName, *ipAddress, *CPU, *RAM, *hardDrive;
+(id)addHostFromPanel:(NSString *)newHostPanel withName:(NSString  
*)newHostName andIpAddress:(NSString *)newIpAddress inGroup:(NSString  
*)newGroup;

@end


I've was trying to add the hosts with the addHostFromPanel method defined above (with a + instead of a -), and implemented like this:
+(id)addHostFromPanel:(NSString *)newHostPanel withName:(NSString  
*)newHostName andIpAddress:(NSString *)newIpAddress inGroup:(NSString  
*)newGroup
{
        // Debug stuff
        NSLog(@"host name passed over is  is %@", newHostName);
        NSLog(@"ip address  passed over is is %@", newIpAddress);
        NSLog(@"the group passed over  is %@", newGroup);
        
        // Here we go!
Host *host = [NSEntityDescription insertNewObjectForEntityForName:@"Host" inManagedObjectContext:[self managedObjectContext]];
        host.hostName = newHostName;
        host.ipAddress = newIpAddress;
        host.group = newGroup;
        
        return host;
}


But, when I try to call this method from my AppController to add the strings to core data, I get an error (as well as a compile warning) that Host can't find it's managedObjectContext.
I'm very new to Cocoa (obviously), and right now I'm very confused.   
I'm sure I'm missing something very basic here, but I've been stuck on  
this for a couple of weeks now.
Thanks in advance for any advice.

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