开发者

What does forKey mean? What does it do?

I'm guessing that it gives the object that is being added to the NSMutable开发者_StackOverflow社区Dictionary or NSDictionary a name to access it. But, I have to confirm it. Can anybody tell me?


Dictionaries are data structures that contain key-value pairs. They're also known as hash tables. So yes, you use a key to refer to its corresponding value.

For the following dictionary:

// Pseudo-code, not actual Objective-C code, merely for illustration
// (This {} syntax would be really nice to have though...)
NSDictionary *dict = {
    @"one" => NSNumber (1),
    @"two" => NSNumber (2)
};

The following code yields 1:

NSNumber *one = [dict objectForKey:@"one"];
NSLog(@"%d", [one intValue]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜