我有两个数组,第一个包含数字,第二个使用这个数字作为索引。
NSArray *dayOfWeek = [NSArray arrayWithObjects:@"D",@"L",@"M", @"X",@"J",@"V",@"S", nil];
NSArray *arrayDays = [days componentsSeparatedByString:@" "];
//arrayDays 2 3 4 5 6
NSString *daysPrint;
for (NSString *theDay in arrayDays) {
NSLog(@"string %@",theDay);
NSInteger dayIndex = (NSInteger)theDay;
NSLog(@"integer %d", dayIndex);
daysPrint = [NSString stringWithFormat:@"%@ %@", daysPrint, [dayOfWeek objectAtIndex:dayIndex]];
}
在日志中:
2012-07-02 12:49:27.322 usualBike[1698:f803] string 2
2012-07-02 12:49:27.323 usualBike[1698:f803] integer 109471840
显然,当我尝试获取 dayOfWeek[109461840] 时,它会崩溃。
我该如何解决这个问题?
先感谢您