我有这个代码,它接受来自Core Data的收入对象数组.
- (void)totalIncome:(NSMutableArray *)IncomesArray {
int i;
int total;
for (i = 0; i < [IncomesArray count]; ++i)
{
Income *income = [IncomesArray objectAtIndex:i];
total += (int)[income value];
NSLog(@"%@", total);
}
self.totalIncomes = [[NSNumber alloc] initWithInt:(int)total];
NSLog(@"%.2f", self.totalIncomes);
}
Run Code Online (Sandbox Code Playgroud)
但行NSLog(@"%@",总计); 导致EXEC BAD ACCESS错误.有没有明显的事我做错了.此外,如果我删除日志,则没有添加到totalIncomes中,在我的头文件中声明为NSNumber.谢谢.