陣列,字典,集合

2021-06-08 15:14:55 字數 1260 閱讀 6321

1.nsstring

初始化方法

- (nsstring *)initwithformat @"%d,%@.....",a,b;

int a = 1000;

nsstring * str1 = [[nsstring alloc] initwithformat:@"zhangsan%d",a];

+ (nsstring *)stringwithformat     

- (nsstring *)initwithstring  @"abc"只能是字串

nsstring * str2 =  [[nsstring alloc] initwithstring:@"姓名:%@" ];

nsstring *str3 = [[nsstring alloc]initwithstring:@"lisi"];

nslog(@"str3 = %p",str3);// str3 = 0x3468 分配在了常量區域,引用計數是乙個寫死的最大值

nslog(@"str3 count = %d",[str3 retaincount]);// str3 count = 4294967295  用%d列印出來-1

用nsstring的時候是產生乙個臨時陣列,不是在原來的陣列裡邊操作

nsmutalestring  增加刪除修改

2.集合(陣列,字典,集合)裡邊只能放物件

陣列 nsarray    可以存放多個物件  每個物件使用下標表示   最後nil結束  ,其成員不必要型別一致。成員必須是物件

nsmutablearray        

字典nsdictionary      用key和value的的形式儲存資料,其物件的儲存也是沒有順序的。每乙個物件都有乙個唯一的key。

nsmutabledictionary

nsset集合裡邊的物件不能重複,元素是無序的。陣列可以重複   。。。。只要是集合,就自己管理記憶體,自己加減

3.nslog(@"%@",物件)就是nslog(@"%@",【物件 description】) 如果有輸出格式方面的要求。可以重寫系統的description方法

4.檢視api

建立乙個物件   

根據大標題找到相關方法 【物件  方法】,有返回值的就接受一下     

sample code     

google

6.initwithstring :@「張三」和 nsstring * str = @「張三」都收在常量區,不會開闢空間,引用計數都是乙個很大的數,而且他們的位址是一樣的。。  用%d ,列印的時候是-1。

集合 陣列,字典

int let numbers 1,2,3,4,5,6,7,8,9,10 for num in numberslet num1 numbers 0 let num2 numbers 1 let array zhangsan lisi 不能向不可變陣列中追加內容 var array1 zhangsan...

OC 學習 陣列,字典,集合

main.m oc 學習 陣列等等 created by binmac on 13 12 6.import int main int argc,const char argv 上面的方法效率很低 for nsstring str3 in marray3 for in實際上是快速列舉,跟for迴圈意義...

陣列 字典 set集合介紹

字典的遍歷 nsdictionary dict nsdictionary dictionarywithobjectsandkeys 第乙個學生 first 第二個學生 second nil nsarray keys dict allkeys id key,value for int i 0 i ke...