資源描述:
《ios中數(shù)組的使用(nsarraynssetnsdictionary)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、我的命運(yùn)我做主http://www.goodprogrammer.org/IOS中數(shù)組的使用(NSArray,NSSet,NSDictionary)line-height:24px">NSArray用于對(duì)象有序集合(數(shù)組) NSSet用于對(duì)象無序集合(集合) NSDictionary用于鍵值映射(字典) 以上三種集合類是不可變的(一旦初始化后,就不能改變) 以下是對(duì)應(yīng)的三種可變集合類(這三種可變集合類是對(duì)應(yīng)上面三種集合類的子類): NSMutableArray NSMutableSet NSMutableDi
2、ctionary 注:這些集合類只能收集cocoa對(duì)象(NSOjbect對(duì)象),如果想保存一些原始的C數(shù)據(jù)(例如,int,float,double,BOOL等),則需要將這些原始的C數(shù)據(jù)封裝成NSNumber類型的,NSNumber對(duì)象是cocoa對(duì)象,可以被保存在集合類中?! ?==================NSArray==================== Orderedcollectionofobjects.Immutable(youcannotaddorremoveobjectstoitoncei
3、t’screated) Importantmethods: +(id)arrayWithObjects:(id)firstObject,...;//nilterminated -(int)count;?????????????????? //得到array中的對(duì)象個(gè)數(shù) -(id)objectAtIndex:(int)index;//得到索引為i的對(duì)象 -(BOOL)containsObject:(id)anObject;??//當(dāng)anObject出現(xiàn)在array中,則返回yes(實(shí)際是通過isEqual:方法來
4、判斷) -(unsigned)indexOfObject:(id)anObject;? //查找array中的anObject,并返回其最小索引值。沒找到返回NSNotFound. -(void)makeObjectsPerformSelector:(SEL)aSelector;-(NSArray*)sortedArrayUsingSelector:(SEL)aSelector; -(id)lastObject;??????????? //得到array中最后一個(gè)對(duì)象。如果array中沒有任何對(duì)象存在,則返回ni
5、l 注: 類方法arrayWithObjects可以創(chuàng)建anautoreleasedNSArrayoftheitems.例如 @implementationMyObject -(NSArray*)coolCats{ return[NSArrayarrayWithObjects:@“Steve”,@“Ankush”,@“Sean”,nil]; } @end Otherconvenientcreatewithmethods(allreturnautoreleasedobjects): [NSStringstr
6、ingWithFormat:@“Meaningof%@is%d”,@“l(fā)ife”,42]; [NSDictionarydictionaryWithObjectsAndKeys:ankush,@“TA”,janestudent,@“Student”,nil]; [NSArrayarrayWithContentsOfFile:(NSString*)path]; -----創(chuàng)建數(shù)組----- NSArray*array=[[NSArrayalloc]最低7000就業(yè),不就業(yè)不交學(xué)費(fèi)我的命運(yùn)我做主http://www.go
7、odprogrammer.org/ initWithObjects:@One,@Two,@Three,@Four,nil]; self.dataArray=array; [arrayrelease]; NSLog(@self.dataArraycountis:%d,[self.dataArraycount]); NSLog(@self.dataArrayindex2is:%@,[self.dataArrayobjectAtIndex:2]); ------從一個(gè)數(shù)組拷貝數(shù)據(jù)到另一數(shù)組(可變數(shù)級(jí))-------
8、 //arrayWithArray: NSArray*array1=[[NSArrayalloc] init];NSMutableArray*MutableArray=[[NSMutableArrayalloc] init]; NSArray*array=[NSArrayarrayWithObj