Array application OC

Source: Internet
Author: User

Array application OC

#import 
 
  #import Person.hint main(int argc, const char * argv[]){    @autoreleasepool {                            NSArray * array = [[NSArray alloc]initWithObjects:@one,@two,@three,nil];        NSLog(@%@,array);                NSArray * array1 = @[@one,@two,@three];        NSLog(@array1 %@,array1);                //int float char double bool        int i = 10;        NSNumber * number = [[NSNumber alloc]initWithInt:i];               NSArray * array2 = @[@one,@two,number];        NSLog(@array2 %@,array2);                      NSArray * a1 = @[@one,@two,@three];        NSArray * a2 = @[@1,@2,@3];        NSArray * a3 = @[a1,a2];                NSString * str = nil;        NSArray * array3 = [[NSArray alloc]initWithObjects:@one,str,a3,@two, nil];        NSLog(@%@,array3);                Person * p1 = [[Person alloc]initWithName:@jack andAge:15];        Person * p2 = [[Person alloc]initWithName:@tom andAge:20];        Person * p3 = [[Person alloc]initWithName:@dick andAge:16];                NSArray * array4 = [[NSArray alloc]initWithObjects:p1,p2,p3,nil];        NSLog(@%@,array4);                       /*         + (NSNumber *)numberWithChar:(char)value;         + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;         + (NSNumber *)numberWithShort:(short)value;         + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;         + (NSNumber *)numberWithInt:(int)value;         + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;         + (NSNumber *)numberWithLong:(long)value;         + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;         + (NSNumber *)numberWithLongLong:(long long)value;         + (NSNumber *)numberWithUnsignedLongLong:(unsign         */                  NSNumber * number1 = [NSNumber numberWithDouble:8.99];        NSNumber * number2 = [NSNumber numberWithFloat:3.1];        NSNumber * number3 = [NSNumber numberWithInt:5];        NSNumber * number4 = [NSNumber numberWithChar:'c'];                NSArray * array5 = [[NSArray alloc]initWithObjects:number1,number2,number3,number4,nil];                       NSLog(@%@,array5);                char c = [[array5 objectAtIndex:3]charValue];        NSLog(@%c,c);                       Person * p4 = [array4 objectAtIndex:1];        NSLog(@%@,p4);                    Person * p5 = array4[1];                NSLog(@%@,p5);                //NSUInteger count = [array5 count];        //NSLog(@%d,count);                                BOOL isContent = [array4 containsObject:p1];        NSLog(@%d,isContent);                if (isContent) {            NSLog(@contain);        }        else        {            NSLog(@no contain);        }            }    return 0;}
 
#import 
 
  @interface Person : NSObject{    NSString * _name;    int _age;}-(id)initWithName:(NSString *)name andAge:(int)age;-(void)setName:(NSString *)name;-(NSString *)name;-(void)setAge:(int)age;-(int)age;@end
 

# Import Person. h @ implementation Person-(id) initWithName :( NSString *) name andAge :( int) age {if (self = [super init]) {_ name = name; _ age = age;} return self;}-(void) setName :( NSString *) name {_ name = name;}-(NSString *) name {return _ name ;} -(void) setAge :( int) age {_ age = age;}-(int) age {return _ age;}-(NSString *) description {return [NSString stringWithFormat: @ name % @ age % d, _ name, _ age] ;}@ end

 

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.