我有自定义类。我想添加到类型为NSDictionary的类属性,该属性将通过给定标签返回此类的属性。但我做不到。有没有可能?我有错误:用自定义类对象创建字典
[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
CODE:
@interface Car : NSObject
@property (nonatomic, strong) NSNumber *topic;
@property (nonatomic, strong) NSNumber *car;
@property (nonatomic, strong) NSDictionary *variables;
@end
@implementation Car
- (NSDictionary *)variables
{
return @{
@"781" : _topic,
@"782" : _car,
}};
@end
你可能会考虑将'variables'设为只读属性,或者更好,只是一个普通的旧方法。 – jlehr 2014-08-30 21:24:37
@jlehr虽然我同意,[这个答案](http://stackoverflow.com/a/10758831/2792531y)似乎表明它可能并不重要。 – nhgrif 2014-08-30 21:33:16