目标C一般打印

Cas*_*ash 15 objective-c

Objective C是否具有像Python这样的通用打印命令?NSLog似乎记录它而不是打印到控制台.printf只接受特定类型.

pho*_*bus 30

NSLog()打印到控制台,与C非常相似printf().在C语言中有其起源和基础,控制台打印基本上是在C语言中完成的.


Dav*_*ong 6

printf是你在找什么.您可以像常规打印声明一样使用它:

printf("This is a neat command!\n");
Run Code Online (Sandbox Code Playgroud)

您也可能意识到可以将其用于替换:

printf("The Answer is %d\n", 42);
Run Code Online (Sandbox Code Playgroud)


Bar*_*ark 6

您可以使用NSString格式化包含id类型的字符串以及标准printf类型,然后使用printf打印它:

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

printf("%s", [fmt cStringUsingEncoding:[NSString defaultCStringEncoding]]);
Run Code Online (Sandbox Code Playgroud)