/*Nsrange Range (location length) nspoint\cgpoint point nssize\cgsize UI element width height nsrect\cgrect*//* NSString Immutable string->nsmutablestring variable string//nsrange r1 = {2, 4}; No//nsrange r2 = {. Location = 2,. length = 4};//without//nsrange r3 = Nsmakerange (2, 4);//Master Nsstr ing *str = @ "I love OC"; Find the range of a string in str//If not found, length=0,location=nsnotfound==-1 nsrange range = [str rangeofstring:@ "Java"]; NSLog (@ "loc =%ld, length=%ld", Range.location, Range.length); The following three are all collection classes Nsarray ordered immutable array->nsmutablearray variable arrays/* Person *p = [[Person alloc] INIT]; Nsarray *array = @[p,@ "Jack"]; /* for (int i = 0;i<array.count;i++) {NSLog (@ "%@", Array[i]); }//id obj represents each element in the array//int i = 0; for (the ID obj in array) {//Find the position of the obj element in the array nsuinteger i = [array indexofobject:o BJ] NSLog (@ "%ld-%@", I, OBJ); i++}*/[Array Enumerateobjectsusingblock://each time you traverse to an element, the block is called//and the current element and index position are passed as parameters to block^(IDobj, Nsuinteger idx,, BOOL *stop) {NSLog (@"%ld-%@", idx, obj); if(idx = =1){ //Stop Traversal*stop =YES; } }]; */nsset Disorder Immutable-nsmutableset variable Nsmutableset*s = [NsmutablesetSet]; [s AddObject:@"ADF"]; Nsdictionary Dictionary-nsmutabledictionary//dictionaries are unordered//allow value to be the same, but key cannot be the samensdictionary*d = @{@"name":@"Jack",@"adrress":@"Leshan"}; Nsmutabledictionary*dict =[Nsmutabledictionary dictionary]; [Dict setobject:@"Jack"Forkey:@"name"]; [Dict setobject:@"Leshan"Forkey:@"adrress"]; [Dict Enumeratekeysandobjectsusingblock:^(IDKeyIDobj, BOOL *stop) {NSLog (@"%@ - %@", key, obj); } /*Dictionary: Key------> Value Index------> Text content Everything stored inside is a key-value pair .*/NSNumber is able to wrap the base data type as an object because it inherits the Nsvalue//wrapping a variety of basic data types into NSNumber objects@ -; @10.5; @YES; @'A';//NSNumber Object @"A";//NSString Object//wrapping The age variable with the scale NSNumber object intAge = -; @ (age); Nsvalue//Structure--->oc objectCgpoint P= Cgpointmake (Ten,Ten); //to convert a struct to a value objectNsvalue *value =[Nsvalue valuewithpoint:p]; //Convert value to the corresponding struct//[value pointvalue];Nsarray*array =@[value]; NSDateintMain () {//09/10/2011NSString *time =@"2011/09/10 18:56"; NSDateFormatter*formatter =[[NSDateFormatter alloc] init]; Formatter.dateformat=@"YYYY/MM/DD hh:mm"; NSDate*date =[Formatter datefromstring:time]; NSLog (@"%@", date); return 0; } voiddate2string () {nsdate*date =[NSDate Date]; //Date Formatting classNSDateFormatter *formatter =[[NSDateFormatter alloc] init]; //y year M month D Day//m min S second h (24) H (12)Formatter.dateformat =@"YYYY-MM-DD HH:mm:ss"; NSString*str =[Formatter stringfromdate:date]; NSLog (@"%@", str); } nsobject*/
Comparison of Nsset and Nsarray 1) Common denominator * are collections, can hold multiple OC objects * can only hold OC object, cannot hold non-OC object type (basic data type: int, char, float, etc., struct, enum) * itself is immutable, there is a mutable subclass 2) different points *nsarray have order, Nsset no order
Oc--foundtation