On 29/10/2009, at 7:02 AM, Russell Finn wrote:

I'm pretty sure you got this backwards -- it's ObjectsAndKeys, not
KeysAndObjects:

attributes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSFont fontWithName:@"Helvetica" size:75], NSFontAttributeName,
      NSColor redColor], NSForegroundColorAttributeName,
      shadow, NSShadowAttributeName,
      nil];

Ref: 
http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDictionary/initWithObjectsAndKeys:
("First the key for firstObject, then a null-terminated list of
alternating values and keys.").

No doubt this was part of the motivation for creating the MYUtilities
library. I'll have to check it out myself.


No, the OP is right. Check again:

initWithObjectsAndKeys:
Initializes a newly allocated dictionary with entries constructed from the specified set of values and keys.

- (id)initWithObjectsAndKeys:(id)firstObject , ...

Parameters
firstObject
The first value to add to the new dictionary.

...
First the key for firstObject, then a null-terminated list of alternating values and keys. If any key isnil, an NSInvalidArgumentException is raised.

The confusion is that the first word on the last line should be 'Then', not 'First'.

Usually when coming up with a method name, it should self-document as far as possible. These nil-terminated lists don't fully do that, but at least the order of words gives you a hint:

initWithObjects(first)andKeys(second)

Therefore the list is ordered object, key, object, key

--Graham


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to