• 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: Binding
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binding


  • Subject: Re: Binding
  • From: Ken Thomases <email@hidden>
  • Date: Tue, 14 Apr 2009 14:14:13 -0500

On Apr 14, 2009, at 11:05 AM, Livio Isaia wrote:

Is it possible to connect a variable of an object I created to an NSArrayController variable?

To be clear: bindings deal with properties, not variables. I don't necessarily mean "declared properties" using @property, but properties in the Key-Value Coding and Key-Value Observing sense.


A property is embodied in the instance methods of your class. If a property is backed by an instance variable, that's an implementation detail. The instance variable is not the property. The methods are.

(Yes, KVC can access instance variables directly, if you let it. You shouldn't let it. That is, you should override +accessInstanceVariablesDirectly to return NO for all of your classes. Allowing KVC to access instance variables directly violates encapsulation and will cause trouble.)


I mean:
I have a NSWindowController "MyWindowController" which is also the nib file's owner type class.

And in the nib you've set the class of File's Owner to MyWindowController?



In the nib file I created an NSArrayController "MyArrayController" connected with a NSTableView.

"MyWindowController" has a variable "seletedItem" and a method (void)setSelectedItem:(NSNumber *)value.

It should also have a -selectedItem method -- the getter for the property.


How can I bind "selectedItem" to a "MyArrayController"'s attribute (e.g selection.item)? And is it possible to do it in InterfaceBuilder (the MyWindowController's bindings Inspector window is just blank)?

It sounds a bit like you're thinking of this backwards. You don't bind from File's Owner to the array controller. You bind from the array controller to File's Owner.


In general, you should only use (or seek to use) bindings that are defined for the classes you're using. For example, the bindings defined for the classes in Cocoa are listed in the Cocoa Bindings Reference <http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/ >. As you can see there's a finite list of classes for which bindings are defined. If you use third-party classes which provide bindings, they should be similarly documented.

Now, NSWindowController does not define any bindings. Likewise, you have presumably not defined any bindings for MyWindowController, and I wouldn't expect you to, based on the typical role of a window controller. Usually, only views and mediating controllers provide bindings. Coordinating controllers and models don't. Window controllers are coordinating controllers.


I'm not sure what you're trying to achieve when you mention a key path of "selection.item" on the array controller. What are you trying to achieve?


Regards,
Ken

_______________________________________________

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: 
 >Binding (From: Livio Isaia <email@hidden>)

  • Prev by Date: Re: Reading in dictionary from txt file: options for speed
  • Next by Date: Re: Best way to get a non-repeating random number?
  • Previous by thread: Binding
  • Next by thread: Garbage collection C++ objects
  • Index(es):
    • Date
    • Thread