NSMutableArray应用

来源:互联网 发布:大众点评待遇知乎 编辑:程序博客网 时间:2024/04/29 09:16

@interface ClassSoftware : NSObject

{
    
    NSString *VerTitle;
    NSInteger VerNum;

}

@property (nonatomic, retain) NSString *VerTitle;
@property (nonatomic, readwrite) NSInteger VerNum;


@end


先申明一个classsoftware类,用于NSMutableArray的存储



NSMutableArray *Mysoftware;  //定义一个可变数组存储对象





*.m


ClassSoftware *software; //申明类

software=[[ClassSoftware alloc]init]; //开辟空间,若不开辟空间,在xcode中不会报错,运行后才会出现异常。

software.vertitle="22222";
software.vernum=21;


Mysoftware=[[NSMutableArray alloc]init];//初始化数组

[Mysoftware addObject:software];//添加对象到数组


 [[Mysoftware objectAtIndex:0]VerTitle] //取值