在 Java 中,我会这样做:
String temp = ".";
System.out.println(temp);
我如何在 Objective-C 中做到这一点?
在 Java 中,我会这样做:
String temp = ".";
System.out.println(temp);
我如何在 Objective-C 中做到这一点?
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");//π
Objective-C 并没有真正拥有自己的专用打印功能。NSLog 将打印您提供的内容以及一堆调试信息。对于直接打印,Cprintf()
仍然是基本标准。作为等效于您的代码,我会写:
NSString *temp = @".";
printf("%s\n", [temp UTF8String]);