Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C General Print

Tags:

objective-c

Does objective C have a general print command like Python? NSLog seems to log it rather than print out to console. printf only accepts specific types.

like image 701
Casebash Avatar asked Jan 12 '10 04:01

Casebash


3 Answers

NSLog() does print to the console, and is very similar to C's printf(). Having its origins and basis in C, console printing is done as it is in C, essentially.

like image 161
phoebus Avatar answered Nov 16 '22 02:11

phoebus


printf is what you're looking for. You can use it like a regular print statement:

printf("This is a neat command!\n");

You're also probably aware that you can use it with substitutions:

printf("The Answer is %d\n", 42);
like image 36
Dave DeLong Avatar answered Nov 16 '22 03:11

Dave DeLong


You can use NSString to format strings containing id types as well as the standard printf types, then just print it using printf:

NSString *fmt = [NSString stringWithFormat:@"My formatted string: %@", anObject];

printf("%s", [fmt cStringUsingEncoding:[NSString defaultCStringEncoding]]);
like image 33
Barry Wark Avatar answered Nov 16 '22 03:11

Barry Wark