开发者

Can NSArray hold NSDictionary in Objective-C/

Can each index of a开发者_如何转开发rray hold the NSDictionary?

Thank You.


Yes, the value of an NSArray can resolve to an object identifier for an NSDictionary. However, the array doesn't "hold" the NSDictionary, nor can the index of an NSArray be an NSDictionary. An index from an Array is always an integer value.


An NSArray can hold any type of object, so yes, putting an NSDictionary in an NSArray works just fine.


You sure can, here is an example:

NSDictionary *dict1 = [[NSDictionary alloc] initWithObjectsAndKeys:
    @"value1", @"key1", @"value2", @"key2", nil];

NSDictionary *dict2 = [[NSDictionary alloc] initWithObjectsAndKeys:
    @"Billy", @"Goat", @"Rover", @"Dog", nil];

NSArray *arrayWithDictionaries = [[NSArray alloc] initWithObjects:
    dict1, dict2, nil];

[dict1 release];
[dict2 release];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜