Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The most basic case is your login controller simply handing a snapshot of the array to the other controller. In this case, your login controller will need to have references to instances of the other classes, and it will set some property of those instances to the array. Remember to declare the properties with the <code>copy</code> attribute, so that the receivers don't hold on to your private mutable array.</p> <p>If you want the other controllers to be able to modify the array, <em>don't</em> let them have your mutable array—that's an invitation to hard-to-find bugs.</p> <p>Instead, you'll need to implement one property on the login controller, instead of one property on each of the other controllers. The login controller's property should have at least a getter and setter (which you can <code>@synthesize</code>), but you can implement <a href="http://boredzo.org/blog/archives/2007-08-07/a-complete-raw-list-of-kvc-accessor-selector-formats" rel="nofollow noreferrer">more specific accessor methods</a> for efficiency.</p> <p>Once you have this property, the other controllers should access the property in a KVO-compliant way. If you implement the specific accessors, they can just use those. Otherwise, they'll need to send <code>mutableArrayValueForKey:</code> to the login controller. When they access the contents of that proxy array, they really access the login controller's array; when they mutate the proxy array, they mutate the login controller's array in turn.</p> <p>Next comes the actual KVO part. You'll want the other controllers to know when one of them (or the login controller) changes the property. Have each controller (except the login controller) add itself as an observer of the property of the login controller. Remember to have them remove themselves in their <code>-dealloc</code> (or <code>-finalize</code>) methods.</p> <p>In order for the right notifications to get posted, everything needs to use either accessors or <code>mutableArrayValueForKey:</code>. That goes for the login controller itself, too—it should use its own accessors when mutating the array, instead of messaging the array directly. The only exceptions are in <code>init</code> and <code>dealloc</code> (because the accessor messages would be messages to a half-<code>init</code>ed/<code>dealloc</code>ked object, which will be a problem if you ever make the accessors fancy*).</p> <p>BTW, it sounds like you may have way too many controllers. See if you can't move some of your logic into model objects instead. That drastically simplifies your code, as Cocoa is designed to work with a model layer. Being controller-heavy is fighting the framework, which makes more work for you.</p> <p>*By “fancy”, I mean doing things other than or in addition to the normal behavior of a given accessor method. For example, <code>insertObject:in&lt;Foo&gt;AtIndex:</code> normally just tail-calls <code>[&lt;foo&gt; insertObject:atIndex:]</code>; if you insert or store the object somewhere other than in an array in an instance variable, or if you do something else in the same method (such as tell a view that it needs to display), then your accessor method is fancy.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload