• 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: Weird behavior in NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird behavior in NSMutableDictionary


  • Subject: Re: Weird behavior in NSMutableDictionary
  • From: Jeremy Dronfield <email@hidden>
  • Date: Sat, 18 Dec 2004 12:06:37 +0000


On 18 Dec 2004, at 10:44 am, Harilaos Skiadas wrote:

From the docs on NSMutableDictionary:

- (void)setValue:(id)value forKey:(NSString *)key

Adds an entry to the receiver using setObject:forKey:
with the >specified value and key. If value is nil it
instead attempts to remove >the specified key using
removeObjectForKey:.

and from NSDictionary:
- (id)valueForKey:(NSString *)key

Returns the result of sending objectForKey: to the
receiver

So it seems to me that as long as the value is not
nil, which it isn't in my case, there is no
difference. Am I missing something?

What you're missing is key value coding. The NSDictionary and NSMutableDictionary docs are strangely disingenuous in their definitions for these methods. -valueForKey: and -setValue:forKey: are not in fact dictionary methods. They are methods in the NSKeyValueCoding informal protocol, which is implemented by NSObject.


It's worth reading up the documentation on this protocol, if only so you know what's going on when you invoke its methods (and what it's limitations and requirements are). One useful feature, for example, is support for non-object parameters and return values, which are wrapped and unwrapped automatically. See:

<file:///Developer/ADC Reference Library/documentation/Cocoa/ Conceptual/KeyValueCoding/index.html#//apple_ref/doc/uid/10000107i>

Regards,
Jeremy

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Weird behavior in NSMutableDictionary
      • From: mmalcolm crawford <email@hidden>
    • Re: Weird behavior in NSMutableDictionary
      • From: Steven Kramer <email@hidden>
References: 
 >Re: Weird behavior in NSMutableDictionary (From: Harilaos Skiadas <email@hidden>)

  • Prev by Date: Re: Bindings problem...
  • Next by Date: Re: Can't use @count with bindings
  • Previous by thread: Re: Weird behavior in NSMutableDictionary
  • Next by thread: Re: Weird behavior in NSMutableDictionary
  • Index(es):
    • Date
    • Thread