开发者

Objective C General Print

开发者 https://www.devze.com 2022-12-16 16:06 出处:网络
Does objective C have a general print command like Python? NSLog seems to log it开发者_StackOverflow中文版 rather than print out to console. printf only accepts specific types.NSLog() does print to th

Does objective C have a general print command like Python? NSLog seems to log it开发者_StackOverflow中文版 rather than print out to console. printf only accepts specific types.


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号