NSUndoManager是否保留其参数?

时间:2012-10-06 08:22:32

标签: cocoa memory-management nsundomanager

以下是由Aaron Hillegas为OS X的书籍可可编程启用撤销的代码:

-(void)removeObjectFromEmployeesAtIndex:(NSUInteger)index
{
Person *p = [employees objectAtIndex:index];
NSLog(@"removing %@ from %@", p, employees);
// Add the inverse of this operation to the undo stack 
NSUndoManager *undo = [self undoManager]; [[undo prepareWithInvocationTarget:self]  insertObject:p inEmployeesAtIndex:index]; 

if (![undo isUndoing]) { 
  [undo setActionName:@"Remove Person"];
} 
[employees removeObjectAtIndex:index];
}

在删除员工时,我们将命令推送到撤消堆栈以将该员工重新插入阵列。但是,当调用撤消时,有什么保证不会被释放?

1 个答案:

答案 0 :(得分:2)

当NSInvocation由“[[undo prepareWithInvocationTarget:self] insertObject:p inEmployeesAtIndex:index]”创建时,

'p'将被保留“