我可以将NSMutableArray声明为共享对象中的属性

时间:2015-08-12 23:25:10

标签: objective-c singleton nsmutablearray instance shared

I / m为iOS 7开发并使用arc。我正在尝试创建一个包含NSMutableArray并且遇到麻烦的shred实例。 在我的头文件中,我有以下

#import <Foundation/Foundation.h>

@interface SharedDataController : NSObject

@property (nonatomic, retain) NSString *text1;
@property (nonatomic, retain) NSString *text2;
@property (nonatomic, retain) NSString *text3;
@property (nonatomic, retain) NSMutableArray *qrcodes;

+(id) sharedInstance;

@end

并且在我的意图中

@synthesize text1,text2,text3, qrcodes;

+(id) sharedInstance
{
    static id sharedInstance = nil;
    if (sharedInstance == nil) {
        NSLog(@"creating shared instance contoller");
        sharedInstance = [[self alloc] init];
    }
    return sharedInstance;
}

@end

当我尝试将对象添加到数组

SharedDataController *sharedDataController = [SharedDataController sharedInstance];

[sharedDataController.qrcodes addObject:result.text];
NSLog(@"%@", sharedDataController.qrcodes);

我没有,我到底做错了什么?

0 个答案:

没有答案