Re: NSDictionary allValues not mutable
Re: NSDictionary allValues not mutable
- Subject: Re: NSDictionary allValues not mutable
- From: Trygve Inda <email@hidden>
- Date: Mon, 18 Oct 2010 21:22:06 +0000
- Thread-topic: NSDictionary allValues not mutable
> You are mistaking instance variables for properties. Instance variables are
> implementation details, and nothing outside of your class should be aware of
> them.
>
> Properties are part of your interface, essentially the accessor methods and
> their behavior. (Remember that you can have properties that are not backed by
> instance variables.)
>
> So, you should be thinking in terms of writing accessor methods which present
> a consistent view of the to-many relationship (which happens to be backed by
> an array and a dictionary). Look up the indexed accessor pattern for to-many
> relationships in the KVC documentation
> <http://developer.apple.com/library/mac/documentation/cocoa/Conceptual/KeyValu
> eCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/20002174-178830-
> BAJEDEFB>. Also, take a look at "Managing a non-array collection, and
> filtering" on mmalc's page of Cocoa examples
> <http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>.
>
> To keep yourself honest, and to help you learn, try making this to-many
> relationship property have a name completely different from the names of the
> instance variables which back it. Also, I generally recommend that all of
> one's own classes should override +accessInstanceVariablesDirectly to return
> NO. (I regard KVC's ability to bypass your interface and directly access your
> instance variables as A Bad Thing™.)
>
> Regards,
> Ken
The example you cited uses:
@class Weapon;
@interface Combatant : NSObject {
NSString *name;
Weapon *weapon1;
Weapon *weapon2;
Weapon *weapon3;
Weapon *selectedWeapon;
int shieldRating;
}
- (unsigned int)countOfWeapons;
- (id)objectInWeaponsAtIndex:(unsigned int)index;
How does it derive the plural for he method name countOfWeapons from the
class name Weapon? What if my Class name was Ox... Surely it would not know
to use countOfOxen ?
I see where one can specify a plural in AppleScripting but not for a Cocoa
class.
Thanks,
T.
_______________________________________________
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