Object c基礎程式設計學習筆記 集合

2021-06-25 07:06:04 字數 1190 閱讀 6267

1、nsarray

首先,nsarray有兩個限制:

1)首先,它只能儲存oc物件,並不能儲存c語言的資料型別

2)其次,不可以儲存nil,因為nsarray中nil代表結束,但是如果我們想要新增乙個空,那麼應該使用nsnull

-(unsigned)count;
這裡可以知道包涵物件的個數

-(id)objectatindex:(unsigned int)index;
這裡可以獲取特定索引處的物件

2、nsmutablearray

-(void) addobject:(id)anobject;
在陣列末尾新增物件

-(void)removeobjectatindex:(unsigned)index;

刪除乙個物件之後,陣列中並沒有留下漏洞,被刪除的物件後面陣列元素都被前移來填補空缺

3、nsdictionary

+(id)dictionarywithobjectsandkeys:(id)firstobject;
tire *t1 = [tire new];

tire *t2 = [tire new];

tire *t3 = [tire new];

tire *t4 = [tire new];

nsdictionary *tires;

tires = [nsdictionary dictionarywithobjectsandkeys:t1,@"front-left",t2,@"front-right",t3,@"back-left",t4,@"back-right",nil];

使用key來獲取物件

-(id)objectforkey:(id)akey;

4、nsmutabledictory

新增元素

-(void) setobject:(id)anobject forkey:(id)akey;

刪除元素

-(void) removeobjectforkey:(id)akey;

Object C學習筆記 基礎篇 基礎語法

還不是很完整 正在努力學習中。類定義 inte ce myclass nsobject property int age end 類實現 implement myclass synthesize age end 多引數方法與呼叫 void setage int age name nsstring s...

object c 學習筆記 一 基礎術語

import intmain int argc,const char ar int count 4 nslog the numbers from 1 to 5 for int i 0 i return0 剛開始學oc,記錄下重點知識,以備及時複習和後續查詢.cocoa ios開發使用的工具包是蘋果公...

Object C學習筆記 高階篇 基礎框架

object c學習筆記 高階篇 不斷更新完善。基礎框架 foundation framework 標頭檔案 import 數字物件 nsnumber 字串物件 如 c program 記憶體中以 0結尾 不可修改字串 nsstring 例 格式化字串 nsstring name xiaoming ...