閱讀863 返回首頁    go 阿裏雲 go 技術社區[雲棲]


NSArry 為靜態數組,不能往裏麵添加元素 NSMutableArray 為動態數組,是NSArray 的子類

NSArry 為靜態數組,不能往裏麵添加元素

NSMutableArray 為動態數組,是NSArray 的子類

定義一個數組

NSarray *city = [[NSArray arrayWithObjects:@"beijing",@"shanghai",@"heibei",nil];

必須以nil結束。

 

方法:

- (undesigned) count  //元素個數

- (id) objectAtIndex: (indesigned) index   //指定位置的元素,可以得到元素

- (undesigned) indexofObjext:(id) object   //對象在元素中的位置

 

(void) addObject:(id)object;  //添加一個元素

 

(void) removeObject:(id);  //從數組中刪除指定元素

 

(void) removeAllObjects:  //刪除所有元素

 

-(bool) containsObject:obj   //是否包含對象

 

(void )insertObject:(id)object  atIndex:(unsigned)index;//在指定位置添加新元素

 

輸出所有元素:

for( int i= 0;i<[city count] ;i++)

{

NSLog(@“%@”,[city objectAtIndex:i] );

}

最後更新:2017-04-04 07:03:09

  上一篇:go NASA 上線開源網站
  下一篇:go 微軟勇敢自嘲:IE變得這麼棒是末日征兆