Accessing CoreData entities
Accessing CoreData entities
- Subject: Accessing CoreData entities
- From: "Bobby B" <email@hidden>
- Date: Sat, 18 Mar 2006 19:17:02 -0400
Hello everyone!
In an effort to help myself learn Cocoa, I've been building a database
application in the form of a phonebook application, with the
possiblity to add a picture of the person. Simple, I know. I stresed
and stressed figuring how to store things in dictionaries, then arrays
(and I bugged the hell out of Paul.) Then, I read the CoreData
tutorial on CocoaDevCentral I was able to implement more functionality
into my program in under 15 minutes then I did in the previous three
days. CoreData is amazing.
I've set up an Entity named "Person" with a handful of properties.
One of the properties is "image" and it's of type "binary." I've
bound the "image" property to the "data" part of the NSImageView on my
Window's form. Everything works fine if you drag-and-drop a picture
into the NSImageView.
However, if I use my load button, it will load and show the picture,
but it doesn't save it into the database. I'm sure there is something
I have to send to the database to tell it that I've modified some
property of the entity.
My load button does the following (very simple)
- (IBAction)loadPicture:(id)sender
{
NSOpenPanel *op = [NSOpenPanel openPanel];
[op runModal];
NSData * myData = [NSData dataWithContentsOfFile:[op filename]];
NSImage * myImage = [[NSImage alloc] init];
[myImage initWithData: myData];
[pictureOutlet setImage:myImage];
[myImage release];
}
I've played around with "didChangeValueForKey", but I'm not sure which
class to send it to, or to tell it which Key I've changed "image"?
"Person"? "pictureOutlet"?
I think what I'm missing is the whole concept of being able to
manually access data in the database. For instance, if I want to have
a count of how many records are in the database, I can't see how to
access it.
My NSArrayControlleris named "Persons". But I can't seem to access
it, or my entity, from within my source code. Do I need to somehow
make my sourcecode aware of it?
Alternatively, are there any "intermediate" Cocoa bindings/CoreData tutorials?
Thank you guys
Bobby B
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden