#import <Foundation/Foundation.h> #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 <Foundation/Foundation.h> @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
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-25 14:40:17