在Java中,我会这样做:
String temp = ".";
System.out.println(temp);
我如何在Objective-C中做到这一点?
答案 0 :(得分:4)
NSString *temp = @".";
NSLog(@"%@", temp);
NSLog格式说明符:
%@ Object, calls the Object's description method
%d, %i signed int
%u unsigned int
%f float/double
%p for pointers to show the memory address
%zu value of type size_t (for sizeof(variable function)
%s C strings
\u can used for arbitrary unicode chars example:NSLog(@"\u03c0");//π
答案 1 :(得分:3)
Objective-C实际上没有自己的专用打印功能。 NSLog将打印您提供的内容以及一堆调试信息。对于直接打印,C printf()
仍然基本上是标准。相当于你的代码,我写道:
NSString *temp = @".";
printf("%s\n", [temp UTF8String]);