2012-03-05 39 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

相关问题