[Oc Study Notes] unchangeable array, oc Study Notes

Source: Internet
Author: User

[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;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.