您的位置:首页 > 移动开发 > Objective-C

iOS: NSDictionary的方法dictionaryWithObjects:forKeys:count:

2013-08-03 08:47 1056 查看
+ (id)dictionaryWithObjects:(const id[])objects forKeys:(const id <NSCopying
>[])keys count:(NSUInteger)count

example:

static const NSInteger N_ENTRIES = 26;

NSDictionary *asciiDict;

NSString *keyArray[N_ENTRIES];

NSNumber *valueArray[N_ENTRIES];

NSInteger i;

 

for (i = 0; i < N_ENTRIES; i++) {

 

    char charValue = 'a' + i;

    keyArray[i] = [NSString stringWithFormat:@"%c", charValue];

    valueArray[i] = [NSNumber numberWithChar:charValue];

}

 

asciiDict = [NSDictionary dictionaryWithObjects:(id *)valueArray

                          forKeys:(id *)keyArray count:N_ENTRIES];

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息