Hi,
I was following the example on Beginning iPhone 3 Development. On Chapter 8 I made a mistake in code.
- (NSMutableDictionary *)mutableDeepCopy
{
NSMutableDictionary * ret = [[NSMutableDictionary alloc] initWithCapacity:[self count]];
NSArray * keys = [self allKeys];
for (id key in keys) {
id oneValue = [self valueForKey:key];
id oneCopy = nil;
if ([oneValue respondsToSelector:@selector(mutableDeepCopy)])
oneCopy = [oneValue mutableDeepCopy];
else if ([oneValue respondsToSelector:@selector(mutableCopy)])
oneCopy = [oneValue mutableCopy];
if (oneCopy == nil)
oneCopy = [oneValue copy];
[ret setValue:oneCopy forKey: key];
}
return ret;
}
In the second responseToSelector, instead of the mutableCopy above, I have mistakenly written it as mutableDeepCopy. As a result my creation of mutable array from the regular one has failed to a simple copy.
As a result console will print error message like this:
2010-02-04 19:58:28.381 Sections[1806:20b] * WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: * -[NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object
Now my question is, this is really hard for me to debug if I'm writing my own code instead of just copying it from book. How do I know at which line this "mutating method sent to immutable object" occurs?