Làm cách nào để tạo một số biến số NSDictionary
bằng cách sử dụng số của mảng?Tạo nhiều biến số được đánh số dựa trên int
Đây là cơ bản những gì tôi đã đưa ra, nhưng tôi không chắc chắn làm thế nào để làm cho công việc này với cú pháp Objective-C. doesntContainAnother
là NSArray
. Tôi muốn tên của các từ điển để sử dụng giá trị hiện tại của loopInt
.
int *loopInt = 0;
while (doesntContainAnother.count <= loopInt) {
NSMutableDictionary *[NSString stringWithFormat:@"loopDictionary%i", loopInt] = [[[NSMutableDictionary alloc] init] autorelease];
[NSString stringWithFormat:@"loopDictionary%i", loopInt] = [NSDictionary dictionaryWithObject:[array1 objectAtIndex:loopInt]
forKey:[array2 objectAtIndex:loopInt]];
loopInt = loopInt + 1;
}
Bạn có thể làm rõ những gì bạn muốn không? Bạn muốn tạo một mảng từ điển mà mỗi từ chỉ chứa một giá trị? – kubi