class.M中的数组以及如何在IT Objective-C中添加值



我想在类中添加一个数组,并给它一些值并在主类中调用。我正在使用

@property(nonatomic) NSArray *subject;

,但我无法从实现类访问它。我想访问它并在其中添加一些随机值。

#import "yourClass.h"
@implementation yourClass
@synthesize subject;
- (void)viewDidLoad 
{
[super viewDidLoad];
subject=[[NSArray alloc]initWithObjects:@"one",@"two",@"three", nil];
}

在您的班级中。合成您的数组

您可以使用_subject

从实现类访问它

Synthesize your property in your `.m file`

喜欢:

@implementation MyClass
@synthesize subject;

最新更新