2012-03-05 37 views

回答

-1

這是可能的。只需創建數組並添加要添加的對象。

+0

感謝您的有益答案 – heziflash 2012-03-08 16:27:17

1

是的,你可以

NSMutableArray *array = [NSMutableArray array]; 
NSString *string = @"str"; 
[array addObject:string]; //string 
NSNumber *num = [NSNumber numberWithInt:1]; 
[array addObject:num]; //int 
NSNumber *boolNum = [NSNumber numberWithBool:YES]; 
[array addObject:boolNum]; //bool 
+0

感謝您的有益答案 – heziflash 2012-03-08 16:27:26

2

只要它們是對象,就可以在NSArray中放置任何項目。因此,您必須將某些對象(如,intCGPoint)中的項目包含在某些對象(如NSNumberNSValue)中。

NSMutableArray *array = [[NSMutableArray] alloc] init]; 

[array addObject:myString]; 

[array addObject:[NSNumber numberWithInt:1]]; 

[array addObject:[NSNumber numberWithFloat:1.0]]; 

[array addObject:[NSValue valueWithPoint:myPoint]]; // myPoint is a CGPoint 

[array addObject:[NSValue valueWithRect:myRect]]; // myRect is a CGRect 
+0

感謝您的有益答案 – heziflash 2012-03-08 16:27:07

0

使用NSMutableArray

NSMutableArray *array = [[NSMutableArray alloc]init]; 

現在使用addObject:方法添加對象。用於添加int,布爾值創建NSNumber對象。

+0

感謝您的幫助解答 – heziflash 2012-03-08 16:26:57

相關問題