Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Doju

macrumors 68000
Original poster
I'm beginning programming in Obj-C, and the book I'm learning from seems to have some typos here and there and this example code the book gave fails to compile.

Code:
// First program example

int main (int argc, const char * argv[])
{
	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	int value1, value2, sum;
	
	value1 = 50;
	value2 = 25;
	sum = value1 + value2;
	
	NSLog (@”The sum of %i and %i is %i”, value1, value2, sum);
	
	[pool drain];
	return 0;
}

Why is that?
 
This is my error:

5odp


Build and Run in Xcode. Yes, that's the complete source.
 
Actually I think the problem is the quotes:

Code:
NSLog (@[COLOR="Red"][B]”[/B][/COLOR]The sum of %i and %i is %i[B][COLOR="Red"]”[/COLOR][/B], value1, value2, sum);

Those should be the normal " character.
 
You need to this import statement at the beginning of your code
Code:
#import <Foundation/Foundation.h>
in order for NSLog to be recognized.

if you have that, then the other problem looks like it is with the smart, or curly, quotes around the string...

Code:
”The sum of %i and %i is %i”
should be
Code:
"The sum of %i and %i is %i"
with straight double quote marks
 
You have to be careful with cut/paste from PDF's. They seem to sneak those damn fancy quotes in when your not looking!
 
Oh, thanks guys. Fixing the quotes fixed the problem. Thanks. 😀

5p4z


And the book is "Programming in Objective-C 2.0".
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.