Casebash
Casebash

Reputation: 118962

Objective C General Print

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.

Upvotes: 16

Views: 23170

Answers (3)

Barry Wark
Barry Wark

Reputation: 107754

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]]);

Upvotes: 6

Dave DeLong
Dave DeLong

Reputation: 243156

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);

Upvotes: 6

phoebus
phoebus

Reputation: 14941

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.

Upvotes: 31

Related Questions