Re: Bindings and C Array
Re: Bindings and C Array
- Subject: Re: Bindings and C Array
- From: Hank Heijink <email@hidden>
- Date: Tue, 12 Dec 2006 10:55:11 -0500
On Dec 12, 2006, at 10:31 AM, Etienne De Sloover wrote:
Hi,
I am still trying to learn Cocoa.
This is my first post on the list.
if I have a class like:
Stuff : NSObject {
...
int thing [ 150 ];
...
}
can I use the bindings with "thing"?
Yes, you can, although to begin with, it would be easier to use your
third option - if you use an NSArray or NSMutableArray, you get a lot
for free. Depending on what 'Stuff' needs to do, you might need the
performance benefit of an int*, but without knowing more about your
project, it's hard to tell. Rule of thumb though: don't start by
optimizing.
That said, review 'Indexed Accessor Patterns for To-Many Properties'
in the Key-Value Coding Programming Guide for info on how to set up
your accessors so you can bind to 'thing'.
Or maybe I would better write:
Stuff : NSObject {
...
int thing000;
int thing001;
...
int thing148;
int thing149;
...
}
This is not a good idea. First of all, it hardwires 150 objects,
requiring you to write 150 accessors. A lot of work, and what if you
decide you need 500 things later? Second, it's completely
counterintuitive. If you need n objects of the same type, you dump
them into some sort of collection, be it an array, a set, or whatever.
Or even
Stuff : NSObject {
...
NSMutableArray *thing;
...
}
I'd go with this to start with. Your bindings will be easy to set up,
and if it turns out to be a performance problem, you can always
change this later without breaking the rest of your code.
Good luck,
Hank
Hank Heijink
www.hankheijink.com
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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