« Core Data, Part 3: Retrieving Data | Main | Core Data, Part 5: Prefilling Data »

September 10, 2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010535e1becf970c0120a5618e6f970b

Listed below are links to weblogs that reference Core Data, Part 4: Inserts, Updates & Deletes:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Dave Gallagher

I just want to say I've read through all your Core Data postings and they've been EXTREMELY helpful. Especially coming from a SQL background. Thanks so much! :)

Arpit

thanks alot..... wonderful tutorials

jj

excuse me for being dense (maybe I should join Densa), but in your first line of code:
CardStack * newStack = (CardStack *)[NSEntityDescription
insertNewObjectForEntityForName:@"CardStack"
inManagedObjectContext:managedObjectContext];

Where does 'CardStack' come from? Is it automatically derived from the model? Or has an object been written which mirrors the structure of the model?

Shannon Appelcline

I created an entity class, which is explained under a major head in Part 2. Otherwise, I just would have referenced a standard managed object class object.

Adham El-Shahabi

Amazing tutorials set. Thank you so much..
greetings from Egypt

Gerald Meazell

OK, another member of Densa here. I've read this series a couple of times and seem to have missed something. In the model for my application, I have a class defined that has attributes and methods for doing certain operations. I want to use Core Data to store the instances of that class. So, I use the method you describe to create a managed object class. I see how I can instantiate the managed object class, but how do I get the data into my domain object? For example:

MyObject : NSObject // Domain class

int id;
NSString *text;

+(VOID) print (
printf(....);
}

MyDataObject // Core Data class

Attributes:
id int64
text String

Do I really have to instantiate both and manually copy the data from one place to the other? I'm hoping there's a simple way to associate these classes and that Core Data keeps up with the changes.

Gerald Meazell

Nevermind. It was covered in Part 2: Creating Entity Classes.

However, this has raised another question. Let's say I'm developing along, and I've generated my classes and have begun building my methods when I discover an attribute I didn't know I needed. If I do the File->New method, it overwrites my files, thus destroying my work on the methods. Is there an elegant way to make changes and integrate them?

Gerald Meazell

Please permit the Densa member to suggest an improvement to your code. When I tried what you did, it complained it "could not locate an NSManagedObjectModel" by the name of 'XYZ' in the context.


I initially thought I had to specify the name elsewhere, then I had an epiphany. When I changed the code to look like this:

CardStack * newStack = (CardStack *)[NSEntityDescription
insertNewObjectForEntityForName:@"CardStack"
inManagedObjectContext:[self managedObjectContext]];

It worked like a charm. The problem is that managedObjectContext is a variable that does not get initialized until you call the getter method and therein lies my chief complaint with Objective C: when you @synthesize a variable, the getter and setter methods have the same name as the variable. So, like in the case above, you think you're calling the method, but in reality you're accessing the variable directly. Putting it in brackets and prepending self calls the getter method, the context is initialized, and all is well.

abhishekparauha@gmail.com

hi this is great content for I-U-D operations .
Can you tell how we create triggers on sqlite DB with manageable object.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment