For anyone following along, the following answers the question I had
regarding adding "records" to a "table" using Core Data:

> Thus (psuedo coded for brevity):
>
> someObject = [NSEntityDescription insertNewObjectForEntityForName:object
inManagedObjectContext:moc];
> [someObject setValue:@"val" forKey:@"foo"];
> [someObject setValue:@"val2" forKey:@"foo2"];
>
> someObject = [...insert...];
> [someObject setValue:forKey:];
> [someObject setValue:forKey:];
>
> someObject = [...insert...];
> [someObject setValue:forKey:];
> [someObject setValue:forKey:];
>
>  ...
>
> [NSManagedObjectContext save:];

When the -insert method is called, Core Data creates an instance of a new
object for an entity and returns a pointer to that object.  By calling
-setValue:forKey: one can then fill in the data values for the required
attributes.  This is different from using default values for attributes as
set by either the data model or via equivalent code.  Those default values
will be automatically populated when the object is created.

Each time the -insert method is called, Core Data continues to create new
instances of objects and return the pointers to them.  someObject is only a
variable that contains that pointer and does not influence the actual object
to which it points other than to point to it.  Thus, re-using someObject
does not obviate the object previously pointed to.

How Core Data manages the created objects isn't anything of concern - the
objects are just managed and kept around in volatile memory.

Once [NSManagedObjectContext save:] is called, those objects are then
committed to the store.

Many thanks to Jerry Krinock for confirming that and fleshing out my
understanding.

Peace, Love, and Light,

/s/ Jon C. Munson II


_______________________________________________

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 arch...@mail-archive.com

Reply via email to