iphone - Cocoa and Cocoa Touch: is an object on the dictionary? -
I thought if an object is on a dictionary, but it appears that it is not. >
I have an NSMutableDictionary with a key called "Product".
Some products have been dynamically added to me, such as
[myDict addObject: @ "banana" for: @ "products"]; [MyDict addObject: @ "orange" for: @ "products"]; [MyDict addObject: @ "Grapes" for: @ "Products"];
etc.
At some point I would like to know that, for example, banana is on the dictionary
Is there a way to do this? I mean, just to know that an object is on the dictionary?
Thanks for any help.
You can put whatever you want in the form of object using ObjectForKey Zero < / Code> will return if the object is not in dictionary and will return the object. You can use it like this:
[myDict addObject: @ "For what you want" : @ "Banana"]; [MyDict addObject: @ "whatever you want" for: @ "orange"]; [MyDict addObject: @ "Whatever You Want" for: @ "Grapefruit"]; .. ([myDict objectForKey: @ "banana"]) {// I've got} if ([myDict objectForKey: @ "orange"]) {// I have an orange} if ([myDict ObjectForKey: @ "Grapes"]) {// I have grapes}
Comments
Post a Comment