Re: IBOutlets or property + binding
Re: IBOutlets or property + binding
- Subject: Re: IBOutlets or property + binding
- From: Keary Suska <email@hidden>
- Date: Fri, 20 Nov 2009 09:43:56 -0700
On Nov 20, 2009, at 2:13 AM, Christian Ziegler wrote:
>
> On 19.11.2009, at 18:45, Keary Suska wrote:
>
>> On Nov 19, 2009, at 10:32 AM, Christian Ziegler wrote:
>>
>>> For instance I got a NSStepper and I only need the integerValue of that stepper. I could either define an IBOutlet and access the integerValue with [stepper integerValue], or I could define a property and bind the steppers value to it. As I mentioned I don't have to manipulate that stepper in any way, I really only need the value. I just wanna know what's best practice.
>>
>> Bindings are generally used to synchronize between a model object and view. When considering a one-way actions, I generally use IBOutlets to manipulate a view, but use target-action for passive activities. So, if it were me, and all I cared about was what value an NSStepper was set to, I would just set the target/action to my controller object and read the value in the action. Although in this case I would set autorepeat to NO so my method is only called once.
>
> In the action method, do you store the changed value in a variable?
You could, although base on the additional information you sent before, an IBOutlet may be a better choice. Keep in mind that there is no real "right way" here. Outlet vs action is simply a stylistic decision, although outlets are a bit more extensible and may make later refactoring a little easier. Bindings, on the other hand, carry both a coding, debugging, and performance overhead that may be unnecessary for simpler operations (or in any case where it isn't sensible to have a model object).
I would finally add that bindings are not *wrong* for your example--they are simply the more complex choice. If you search the archives you will find developers who shun them religiously, and others who swear by them. I like them personally for many things, but avoid them in situations where they needlessly over-complexify my design.
HTH,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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