• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: I can't supply document reference to (init) with bindings, can I?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I can't supply document reference to (init) with bindings, can I?


  • Subject: Re: I can't supply document reference to (init) with bindings, can I?
  • From: David Hirsch <email@hidden>
  • Date: Sun, 29 Nov 2009 17:48:57 -0800

Hi Graham-
Getting the object's document model is precisely what my goal is. I realize that the currentDocument is a bad way to get this (and I more or less said that in the OP, but perhaps not clearly enough), but without some special magic, how am I to get a document reference to the object that gets created by a NSArrayController using add:? I guess I will have to subclass NSArrayController just for this purpose, as the other respondent said. I was hoping that there might be a code- less, IB-bindings-only way to do this, since it seems like it would be a common problem.
Thanks,
-Dave


On Nov 29, 2009, at 4:54 PM, Graham Cox wrote:


On 30/11/2009, at 10:31 AM, David Hirsch wrote:

I'm trying to use bindings as much as possible, but I think I need to do this with actions & outlets. I have a NSArrayController (courseController) managing an NSMutableArray (courses) of Course objects. In order to correctly initialize each Course, I need to have data from other arrays (like the rooms array) that my document knows about. In (init), I tried to use the sharedDocumentController to get the current document, but in reading online, that seems to be unwise (what if the window or application is not frontmost), and furthermore, it seems not to work: I cannot get a reference to the current document from the sharedDocumentController, for some reason.

So: is there some tricky way to have the "add new course" button tell the courseController to add a new Course, but somehow call a custom init (like init:withDocument:) and supply some reference to the current document? I doubt it, but it seems worth asking.

Thanks in advance.
-Dave


It sounds like an architectural muddle.

A 'document' is part of the data model, but the idea of the 'current document' is really dependent on the document associated with the active window, which is a view. A data model in and of itself should not be concerned with which window is active, since that violates MVC.

What does each document represent? Typically a document will represent one example of the main 'thing' that your app deals with, and so often owns or embodies an instance of the data model. If parts of that data model need the document they belong to, then you can easily arrange a way for them to get it, without relying on which document is current, which is likely to set up unwanted dependencies and strange behaviours that will be hard to control.

Work out your architecture properly before worrying about some of the implementation details, like what you can call from an -init method. A clean, clear architecture usually makes the implementation obvious.

--Graham



============================
Dave Hirsch
Associate Professor
Department of Geology
Western Washington University
persistent email: email@hidden
http://www.davehirsch.com
voice: (360) 389-3583
aim: email@hidden
vCard: http://almandine.geol.wwu.edu/~dave/personal/DaveHirsch.vcf
============================



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


References: 
 >I can't supply document reference to (init) with bindings, can I? (From: David Hirsch <email@hidden>)
 >Re: I can't supply document reference to (init) with bindings, can I? (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Apple MVC and Document Based application confusion.
  • Next by Date: Re: Keyword @defs
  • Previous by thread: Re: I can't supply document reference to (init) with bindings, can I?
  • Next by thread: Apple MVC and Document Based application confusion.
  • Index(es):
    • Date
    • Thread