newbi
newbi

Reputation: 21

How do I do the equivalent of println in Objective-C?

In Java, I would do this:

String temp = ".";
System.out.println(temp);

How might I do that in Objective-C?

Upvotes: 2

Views: 6956

Answers (2)

Parag Bafna
Parag Bafna

Reputation: 22930

NSString *temp = @".";    
NSLog(@"%@", temp);  

NSLog format specifiers:

%@ Object, calls the Object's description method
%d, %i signed int
%u unsigned int
%f float/double
%p for pointers to show the memory address
%zu value of type size_t (for sizeof(variable function)
%s C strings
\u can used for arbitrary unicode chars example:NSLog(@"\u03c0");//π

Upvotes: 5

Chuck
Chuck

Reputation: 237100

Objective-C doesn't really have its own dedicated printing function. NSLog will print what you give it along with a bunch of debugging information. For straight-up printing, the C printf() is still basically the standard. As the equivalent to your code, I'd write:

NSString *temp = @".";
printf("%s\n", [temp UTF8String]);

Upvotes: 5

Related Questions