類型objective-c |
常量實例ide |
NSlog字符this |
Charurl |
‘a’,’/n’spa |
%c.net |
Short int指針 |
--orm |
%hi,%hx,%ho對象 |
Unsigned short intblog |
-- |
%hu,%hx,%ho |
Int |
12,-97,0xFFE0,0177 |
%i,%x,%o |
Unsigned int |
12u,100U,0xFFu |
%u,%x,%o |
Long int |
12L,-200l,0xffffL |
%li,%lx,%lo |
Unsigned long int |
12UL,100ul,0xffeeUL |
%lu,%lx,%lo |
Long long int |
0xe5e5c5e5LL,500ll |
%lli,%llx,%llo |
Unsigned long long int |
12ull,0xffeeULL |
%llu,%llx,%llo |
Float |
12.34f,3.1e-5f, |
%f,%e,%g,%a |
Double |
12.34,3.1e-5,0x.1p3 |
%f,%e,%g,%a |
Long double |
12.34l,3.1e-5l |
%Lf,%Le,%Lg |
id |
nil |
%p |
NSLog定義在NSObjCRuntime.h中,以下所示:
void NSLog(NSString *format, …);
基本上,NSLog很像printf,一樣會在console中輸出顯示結果。不一樣的是,傳遞進去的格式化字符是NSString的對象,而不是chat *這種字符串指針。
NSLog能夠以下面的方法使用:
NSLog (@"this is a test");
NSLog (@"string is :%@", string);
NSLog (@"x=%d, y=%d", 10, 20);
可是下面的寫法是不行的:
int i = 12345;
NSLog( @"%@", i );
緣由是, %@須要顯示對象,而int i明顯不是一個對象,要想正確顯示,要寫成:
int i = 12345;
NSLog( @"%d", i );
NSLog的格式以下所示: