[Oc Study Notes] unchangeable array, oc Study Notes
NSArray * aa = [[NSArray alloc] init]; NSArray * aaa = [NSArray array]; // declare a single content array NSArray * aaaa = [NSArray arrayWithObject: @ "sd"]; // declare multiple Content arrays NSArray * arr = [NSArray arrayWithObjects: @ "SDS", @ "Dsad", nil]; // NSLog (@ "% zi", arr. count); // The NSLog object corresponding to a subscript in the array (@ "% @", [arr objectAtIndex: 1]); // NSLog (@ "% @", [arr lastObject]) of the last corresponding object in the array; // The subscript NSLog (@ "% zi ", [arr indexOfObject: @ "Dsad"]); // write the NSString * path = @ "/Users/XuLee/Desktop/oc/abc.txt"; [arr writeToFile: path atomically: YES]; // The read file must be in the specified format NSString * ff = [NSArray arrayWithContentsOfFile: path]; // concatenate an object in the array into a string NSString * fg = [arr componentsJoinedByString: @ "-"]; // array traversal // normal traversal mode for (int I = 0; I <arr. count; I ++) {id obj = [arr objectAtIndex: I]; NSLog (@ "% @", obj) ;}// fast traversal for (id obj in arr) {NSLog (@ "% @", obj);} // code block traversal [arr enumerateObjectsUsingBlock: ^ (id obj, NSUInteger idx, BOOL * stop) // If obj is the element idx and the subscript stop is equivalent to the loop ends when break stop is yes {NSLog (@ "% @", obj ); // The stop value is in the form of * stop = yes or no}]; // The iterator traverses // load each element in the array into NSEnumerator * vv = [arr objectEnumerator] In the iterator; id obj = nil; while (obj = [vv nextObject]) {NSLog (@ "% @", obj);} // reverse iteration NSEnumerator * vvv = [arr reverseObjectEnumerator]; while (obj = [vvv nextObject]) {NSLog (@ "% @", obj );} // Let the array call a uniform method Student * stu1 = [[Student alloc] init]; stu1.name = @ "fff"; Student * stu2 = [[Student alloc] init]; stu2.name = @ "hhh"; NSArray * aee = [NSArray arrayWithObjects: stu1, stu2, nil]; [aee makeObjectsPerformSelector: @ selector (sayHi)]; // Let the array call the method of a certain parameter [aee makeObjectsPerformSelector: @ selector (study :) withObject: @ "math"];
-(NSString *)description{ NSString *aa = [NSString stringWithFormat:@"%@",_name]; return aa;}-(void)sayHi{ NSLog(@"my name %@",_name);}-(void)study:(NSString *)ss{ NSLog(@"%@ study %@",_name,ss);}
@property (nonatomic,strong)NSString *name;-(void)sayHi;-(void)study:(NSString *)ss;