想给nsdictionary
的key
添加一个数组,其中每个key
都是一个question
,每个question
对应多个answer
:
Question1 = [Answer1], [Answer2] , [Answer3];
Question2 = [Answer1], [Answer2] , [Answer3];
然后我尝试用下面的代码时报错:
`
No Visible @interface for NSDictionary declares the selector 'setObject::forKey'
`
代码:
//answers
_surveyAnswers1 = [[NSMutableDictionary alloc] init];
NSArray *myArrayAnswers1 = [NSArray arrayWithObjects:@"One",@"Two", nil];
NSArray *myArrayAnswers2 = [NSArray arrayWithObjects:@"Three",@"Four", nil];
[_surveyAnswers1 setObject:myArrayAnswers1 forKey:@"FirstKey"];
[_surveyAnswers1 setObject:myArrayAnswers2 forKey:@"SecondKey"];
不知道怎么正确添加?
你好像把_surveyAnswers1
声明为NSDictionary
了:
`
NSDictionary * _surveyAnswers1;
`
应该声明为NSMutableDictionary:
`
NSMutableDictionary * _surveyAnswers1;
`
编译器根据声明的类型来判断哪些方法是有效的,NSDictionary
没有这个方法setObject:forKey:
,因此编译器会发出警告
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。