我试图创建一个属性为getter - 暂时我只是用的方法从静态数组建立一个NSMutableObject但最终这些都将是动态的配置设置。在以前的应用程序,从getter and setters not working objective c我这样做:自吸气不叫目标C
#import "ViewController.h"
@interface ViewController()
@property (nonatomic) NSMutableDictionary *questions;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[self questions] setValue:@"FOO" forKey:@"bar"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
+ (NSMutableDictionary *)questions
{
static NSMutableDictionary *_questions;
if (_questions== nil)
{
NSArray *genders = @[@"male", @"female"];
NSArray *ages = @[@"<10", @">60", @"Other"];
_questions = [[NSMutableDictionary alloc] init];
[_questions setValue:genders forKey:@"gender"];
[_questions setValue:ages forKey:@"age"];
}
return _questions;
}
当我在viewDidLoad中的线,我尝试使用“问题”属性,它不使用自定义的吸气剂(它只是分配栏:FOO到零字典)。我错过了什么?
事实上,我怀疑操作系统的意图是使它成为一个实例方法:'(NSMutableDictionary *)questions'(将领先的“+”改为“ - ” –