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

来源:互联网 发布:微信换群软件 编辑:程序博客网 时间:2024/05/29 18:11

+ (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];