Hi, I have a simple class with an NSMutableDictionary member variable. However, when I call setObject:forKey I get an error ('mutating method sent to immutable object'). The source of the problem is obvious from the debugger -- my NSMutableDictionary is actually of type NSDictionary.
I must be missing something incredibly simple but can't seem to fix it. Here is the relevant code:
// Model.h
@interface Model : NSObject {
NSMutableDictionary *piers;
}
@property (nonatomic,retain) NSMutableDictionary *piers;
@end
// Model.m
@implementation Model
@synthesize piers;
-(id) init {
if (self = [super init]) {
self.piers = [[NSMutableDictionary alloc] initWithCapacity:2];
[self createModel];
}
return self;
}
-(void) createModel {
[piers setObject:@"happy" forKey:@"foobar"];
}
@end
If I put a breakpoint anywhere in the code and investigate self.piers, it is of type NSDictionary. What am I missing so that it is treated as an NSMutableDictionary instead? Thanks!