程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C >> 關於C >> 數組的應用OC

數組的應用OC

編輯:關於C
#import 
#import Person.h
int 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:@名字%@ 年齡%d,_name,_age];
}
@end

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved