Skip navigation.
 
mlRe: Question about Saving a document
FROM : Francis Derive
DATE : Thu Jun 15 12:15:08 2006

On Jun 14, 2006, at 10:45 PM, Paul Lynch wrote:
> On 14 Jun 2006, at 11:48, Francis Derive wrote:
>

>> Paul,
>>
>>  You say "You don't want to have your model instantiated in the 
>> nib" but, in the Apple's "Developing Cocoa Applications Using 
>> Bindings: A Tutorial", this is what is made : an instance of the 
>> model named "Converter" is instanciated in the nib, then an 
>> instance of an NSObjectController - the content of which is the 
>> above model, etc...

>
> You shouldn't assume that Apple examples all follow best practices 
> (they try, but can't always succeed), nor that their examples are 
> always entirely typical usages.



Paul,
   I had envisage this argument - an example always being a toy-example 
- but I can't be convinced about what would seem a deficiency as I 
will show.


>> What could I do from a nib if there were nothing in it ?

>
> This question indicates that you haven't understood the example 
> very well.


   That's so much true, and many thanks for taking care.

> A nib will certainly contain many view objects (windows, buttons, 
> fields, etc), as well as instantiated controllers, both bindings 
> controllers and your own classes.
> Your controller objects will interact with both view objects, and 
> model objects.  Most commonly, model objects are instantiated 
> inside your controllers.  In a few cases, and the CurrencyConverter 
> is one, you can have a model object that is instantiated inside the 
> nib, simply because it is convenient to do so.


   "simply because it is convenient to do so" - but isn't it why nibs 
can be so useful, I mean even in *real scale examples* ?
   If you are right, I immediately rework ( I had done it, and I do it 
again here ) this currency converter example by
       - deleting the Converter NSObject instance ( the Model ) from the 
nib, and
       - I create an NSDocument subclass with, as you said, an instance 
variable set to the model object ( I will have to show you how I do 
that, because I had doubts about my doing that ).

   But this point : do I keep in the nib the Object Controller ( the 
content of which had been set to the above model object in IB ), or 
do I delete it also ?
   If I were to keep it in the nib, I would have to do the connection 
between this Object Controller and its model object - which is now an 
instance variable of the above NSDocument subclass. Programmatically, 
by a setContent method - if I am not wrong ?
   Again, it will be hard to believe that IB was useful only for this 
toy example !

> You need to implement a connection from your document controller to 
> the converter object,


   "document controller" ? Isn't going too far ?
> and refer to it in the load and save methods.  See previous posts. 
> However, there isn't any reasonable way to implement load 
> functionality unless you move the converter object inside your 
> controller, as you can't just replace the nib instantiated object. 
> Again, see previous posts.
>
> You aren't going to be able to simply "extend" this example; 
> sometimes, you have to make changes to previous approaches into 
> order to move forwards.


   I am ready to make changes to what is a toy-example - and I want to 
learn how to do that -, but if extending the case for what is only 
but a little step forward ( saving/reading to/from a file ) is too 
much so that the toy-example succumbs to show evidence of anything 
worth, where are we going to with Cocoa bindings.
   I am still convinced there is a way to do it.

> Perhaps some of the Apple documentation people on this list will 
> take your suggestion and update the tutorial for you.
>
> Paul


   Many thanks to you.

Francis.

Related mailsAuthorDate
mlQuestion about Saving a document Francis Derive Jun 5, 12:42
mlRe: Question about Saving a document Paul Lynch Jun 5, 12:50
mlRe: Question about Saving a document Francis Derive Jun 5, 16:16
mlRe: Question about Saving a document Paul Lynch Jun 5, 17:28
mlRe: Question about Saving a document Francis Derive Jun 14, 12:48
mlRe: Question about Saving a document Paul Lynch Jun 14, 22:45
mlRe: Question about Saving a document Francis Derive Jun 15, 12:15
mlRe: Question about Saving a document Paul Lynch Jun 17, 17:27