Re: Core Data: Single entity in NSDocument?
Re: Core Data: Single entity in NSDocument?
- Subject: Re: Core Data: Single entity in NSDocument?
- From: Jim Correia <email@hidden>
- Date: Fri, 7 Jul 2006 09:03:36 -0400
On Jul 6, 2006, at 12:26 PM, Michael Anckaert wrote:
I have a Core Data application with a NSDocument structure. I want
each NSDocument to have only 1 entity, not an array of entities.
If I create an entity called Ent1, I can only display a list of
entities in my document, using an array controller and the
selection control key.
How can I only have 1 entity in my document? So instead of an array
controller, I'd need an object controller or something.
Is this possible with Core Data?
You question seems to conflate Core Data with Cocoa bindings. Core
Data and Cocoa bindings are separate, complimentary things. mmalc's
old post is worth reading here.
<http://www.cocoabuilder.com/archive/message/cocoa/2006/4/5/160303>
So you have two problems:
1) How to I have only 1 instance of Ent1 in my document?
The generic answer is to perform a fetch for instances of Ent1 and if
you don't get any back insert one.
In the case of a document based application the answer is more simply
just insert an instance of Ent1 in -initWithType:error:. See the
EventManager example.
2) How to I make the controllers work for one instance instead of many?
Using Cocoa Bindings, the answer here is NSObjectController, as you
guessed. The Xcode data modeler and Interface Builder will create a
prototype interface for you by option-dragging your entity to the
content of your document window. You can study the prototype
interface to understand how it works, then extend it (or start from
scratch.)
Jim
_______________________________________________
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