我按照教程的说明进行操作,但我无法弄清楚什么是错误的。我已经加倍检查了一切。我将编译器错误放在下面的代码注释中。对不起,这可能会显示我是多少个noob。Xcode中的未知错误
// main.m
#import <Foundation/Foundation.h>
#import "LotteryEntry.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Creates the date object
NSCalendarDate *now = [[NSCalendarDate alloc]init];
//Seed the random number generator
srandom(time(NULL));
NSMutableArray * array;
array = [[NSMutableArray alloc]init];
int i;
for (i = 0; i < 10; i++) {
//create a date/time object that is 'i' weeks from now
NSCalendarDate *iWeeksFromNow;
iWeeksFromNow = [now dateByAddingYears:0
months:0
days:(i * 7)
hours:0
minutes:0
second:0];
}
//create the LotteryEntry object
LotteryEntry *newEntry = [[LotteryEntry alloc]init];
[newEntry prepareRandomNumbers];
[newEntry setEntryDate: iWeeksFromNow];
//Error says "Use of undeclared identifier "iWeeksFromNow'. Did I not declare it above?
//add the lottery entry object to the array
[array addObject:newEntry];
}
for (LotteryEntry *entryToPrint in array) {
//Error says " Expected identifier or '('
//Display it's contents
NSLog(@"%@", entryToPrint);
}
[pool drain];
return 0;
//Error says " Expected identifier or '('
}
//Error says " Expected External declaration
呀,黑青蛙是正确的,for循环剪短中存在,它应该去} [阵列ADDOBJECT:newEntry]下,而不是仅仅在iWeeksFromNow之后 – jcane86 2011-04-06 18:54:15