Hi all,
First of all I am new to programming in XCode and Cocoa but not new to programming. I do know C/C++, and have developed applications for MS Windows using VS and VB, and on the Mac using RB. I started reading the book "Cocoa Programming for Mac OS X - 3rd Edition" and got to a point when the example program will not compile. Please bear with me since I am new to XCode. I am on Mac OS X 10.4.11 and using XCode 2.5. This is the lastest release for 10.4 according to Apple.
Here is the code snippet:
So far from what I can understand from this example is that it appears that a for loop can enumerate an array of objects like For-With loops in VB/RB. Or at least that is my understanding.
The errors occur on the second for statement. I get these errors:
error: nested functions are disabled, use -fnested-functions to re-enable
error: syntax error before 'in'
The obvious thing to me was to comment out the whole second for statement and see if it compiled, which it does. I cannot figure out what the problem is or how to change the switch when it compiles.
There were 2 warnings, but I figured like any other C compiler warnings that these may be a result of the initial errors.
Any help will greatly further my understanding. So far what I have seen in objective-c, I really like it more than C++. Coming from REALbasic and VB this is great so far. I think I can change the for() loop to use a regular index and parse through the array in a standard fashion.
I would like to understand why I am getting the error. I am assuming, of course, that the code in the book is correct since I could not find any corrections to the book at the web site, which is where I first looked.
Thank you in advance.
First of all I am new to programming in XCode and Cocoa but not new to programming. I do know C/C++, and have developed applications for MS Windows using VS and VB, and on the Mac using RB. I started reading the book "Cocoa Programming for Mac OS X - 3rd Edition" and got to a point when the example program will not compile. Please bear with me since I am new to XCode. I am on Mac OS X 10.4.11 and using XCode 2.5. This is the lastest release for 10.4 according to Apple.
Here is the code snippet:
Code:
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
seconds:0];
// Create a new instance of LotteryEntry
LotteryEntry *newEntry = [[LotteryEntry alloc] init];
[newEntry prepareRandomNumbers];
[newEntry setEntryDate:iWeeksFromNow];
// Add the LotteryEntry object to the array
[array addObject:newEntry];
}
for (LotteryEntry *entryToPrint in array)
{
// Display its contents
NSLog(@"%@", entryToPrint);
}
So far from what I can understand from this example is that it appears that a for loop can enumerate an array of objects like For-With loops in VB/RB. Or at least that is my understanding.
The errors occur on the second for statement. I get these errors:
error: nested functions are disabled, use -fnested-functions to re-enable
error: syntax error before 'in'
The obvious thing to me was to comment out the whole second for statement and see if it compiled, which it does. I cannot figure out what the problem is or how to change the switch when it compiles.
There were 2 warnings, but I figured like any other C compiler warnings that these may be a result of the initial errors.
Any help will greatly further my understanding. So far what I have seen in objective-c, I really like it more than C++. Coming from REALbasic and VB this is great so far. I think I can change the for() loop to use a regular index and parse through the array in a standard fashion.
I would like to understand why I am getting the error. I am assuming, of course, that the code in the book is correct since I could not find any corrections to the book at the web site, which is where I first looked.
Thank you in advance.