I have a class that has a NSMutableDictionary
as a property:
@interface Alibi : NSObject <NSCopying>
@property (nonatomic, copy) NSMutableDictionary * alibiDetails;
@end
With the following constructor:
- (Alibi *)init
{
self = [super init];
_alibiDetails = [NSMutableDictionary dictionary];
return self;
}
and copy method:
- (Alibi *)copyWithZone:(NSZone *)zone
{
Alibi *theCopy = [[Alibi alloc] init];
theCopy.alibiDetails = [self.alibiDetails mutableCopy];
return theCopy;
}
When I try to call setObject:ForKey:
I get a runtime error mutating method sent to immutable object
.
I have the Alibi
object declared in the view controller as @property (copy, nonatomic) Alibi * theAlibi;
and I initialize it with self.theAlibi = [[Alibi alloc] init];
in viewDidLoad
.
The line which crashes is:
NSString * recipient;
recipient = @"Boss";
[self.theAlibi.alibiDetails setObject:recipient forKey:@"Recipient"];
Please let me know what I am doing wrong here. I am coding for iOS 5 on iPhone.