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.
+8
A:
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.
phoebus
2010-01-12 04:44:36
Was about to say the same thing! +1
Jacob Relkin
2010-01-12 04:45:51
Oh, I left out the @ - still new to objective C
Casebash
2010-01-12 05:03:17
(Was testing it with a string)
Casebash
2010-01-12 05:03:50
NSLog(@"%@", myObject); will achieve the desired goal.
Casebash
2010-01-13 00:14:09
A:
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);
Dave DeLong
2010-01-12 04:45:57
+2
A:
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]]);
Barry Wark
2010-01-12 05:22:29
It should be `printf("%s",[fmt cStringUsingEncoding:…])`, to cover the case where the string already has a '%' in it.
Chris Johnsen
2010-01-12 06:45:48