NSLog學習筆記 (一)
来源:互联网 发布:java基础程序设计步骤 编辑:程序博客网 时间:2024/05/29 17:46
都知道用NSLog可以輸出一些程序運行的信息,但原來可以直接NSLog一個陣列,如:
NSArray *tests = [NSArrayarrayWithObjects:@"hello",@"this",@"is",@"a",@"test",nil];
NSLog(@"%@",tests);
會輸出:
2012-07-09 15:29:12.146 test20120709[15649:f803] (
hello,
this,
is,
a,
test
)
但如果將上面改為:
NSArray *tests = [NSArray arrayWithObjects:@"hello",@"this",@"is",@"a test", nil];
NSLog(@"%@",tests);
則輸出為:
2012-07-09 15:31:42.472 test20120709[15695:f803] (
hello,
this,
is,
"a test"
)
也就是說,一個空格鍵,使得它將@"a test"看作是一個字符串。但如果直接打"NSArray *tests = [NSArray arrayWithObjects:hello,this,is,a,test, nil];"就會出錯了。奇怪。
以下代碼先建立字符串對象,這樣就得到不受影響的結果:
NSString *string1 =@"hello, this is";
NSString *string2 =@"a test";
NSArray *tests = [NSArrayarrayWithObjects:string1,string2,nil];
NSLog(@"%@",tests);
輸出:
2012-07-09 16:02:03.042 test20120709[15994:f803] (
"hello, this is",
"a test"
)
嘗試在陣列中加入非字符串NS對象:
NSString *string1 =@"hello, this is atest";
NSError *error =NULL;
NSArray *tests = [NSArrayarrayWithObjects:string1,error,nil];
NSLog(@"%@",tests);
輸出為如下,注意只有一行,error對象仿佛不存在:
2012-07-09 16:04:59.255 test20120709[16026:f803] (
"hello, this is atest"
)
極端做法,在陣列中加入UI對象,結果十分有趣!
NSString *string1 =@"hello, this is atest";
UIButton *testButton = [[UIButtonalloc]init];
[testButtonsetTitle:@"test"forState:UIControlStateNormal];
NSArray *tests = [NSArrayarrayWithObjects:string1,testButton,nil];
NSLog(@"%@",tests);
輸出如下:
2012-07-09 16:07:57.158 test20120709[16093:f803] (
"hello, this is atest",
"<UIButton: 0x68afd80; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x68afe40>>"
)
- NSLog學習筆記 (一)
- Swift学习,NSLog的使用(一)
- OC学习旅程(一)NSLog 和 类的创建
- NSLog
- NSLog
- NSLog
- NSLog
- NSLog
- NSLog
- nslog
- NSLog
- NSLOg
- NSLog
- NSLog
- NSLog
- 如何使用 CCLOG(NSlog)
- 黑马程序员---description方法(NSLog输出)
- Swift Release模式下屏蔽NSLog()
- Android ApiDemos示例解析(61):Graphics->Compass
- linux的mount(挂载)命令详解
- php 利用 strip_tags() 函数去除 html元素
- Ubuntu下编译VLC2.0.1
- PyQuery读写html文件
- NSLog學習筆記 (一)
- get_called_class,get_parent_class,is_subclass_of
- javascript中的void运算符
- Android开发之ListView 适配器(Adapter)优化
- 编写高效的Android代码
- 360特供机AK47 PK 华为P1:配置相近,体验有差距
- linux 日志
- Hibernate级联操作
- ext2.0.2+jsp分页简单实现