У меня проблемы с операцией отмены. Следующий код не отменяет операцию removeObjectForKey:
, но операция восстановления setObject:ForKey:
работает.
- (void) insertIntoDictionary:(NSBezierPath *)thePath
{
[[[window undoManager] prepareWithInvocationTarget:self] removeFromDictionary:thePath];
if(![[window undoManager] isUndoing])
[[window undoManager] setActionName:@"Save Path"];
NSLog(@"Object id is: %d and Key id is: %d", [currentPath objectAtIndex:0], thePath);
[colorsForPaths setObject:[currentPath objectAtIndex:0] forKey:thePath];
}
- (void) removeFromDictionary:(NSBezierPath *)thePath
{
[[[window undoManager] prepareWithInvocationTarget:self] insertIntoDictionary:thePath];
if(![[window undoManager] isUndoing])
[[window undoManager] setActionName:@"Delete Path"];
NSLog(@"Object id is: %d and Key id is: %d", [colorsForPaths objectForKey:thePath], thePath);
[colorsForPaths removeObjectForKey:thePath];
}
Вывод на консоль выглядит так:
// Before setObject:ForKey:
Object id is: 1183296 and Key id is: 1423872
// Before removeObjectForKey:
UNDO
Object id is: 0 and Key id is: 1423872
Я не понимаю, почему идентификатор объекта отличается, хотя идентификатор ключа остается прежним. Есть ли специальная обработка отмены / повторения NSMutableDictionary
объектов?
ТНХ
xonic