1

在 Java 中,我会这样做:

String temp = ".";
System.out.println(temp);

我如何在 Objective-C 中做到这一点?

4

2 回答 2

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");//π
于 2012-05-19T05:54:53.353 回答
4

Objective-C 并没有真正拥有自己的专用打印功能。NSLog 将打印您提供的内容以及一堆调试信息。对于直接打印,Cprintf()仍然是基本标准。作为等效于您的代码,我会写:

NSString *temp = @".";
printf("%s\n", [temp UTF8String]);
于 2012-05-19T05:58:39.427 回答