Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试创建一个字符串数组并尝试使用下面的代码。这将创建带有垃圾数据的数组。谁能解释我为什么会这样?
NSString *str[2];
str[0] = @"欢迎";
NSString *str = [array objectAtIndex:0];
--- iOS 7 更新 ---
iOS 7 SDK 现在公开firstObject在数组上公开一个方法,如果数组为空,该方法不会抛出越界异常。它可以这样使用:
firstObject
NSString *str = [array firstObject]; if(str != nil){ // Your code here }else{ // Array was empty }