NSUndoManager 延迟参数评估
NSUndoManager Delayed Argument Evaluation
我正在尝试使用 NSUndoManager 的 prepareWithInvocationTarget。我想要像
这样的东西
[[self.undoManager prepareWithInvocationTarget:self] doSomethingWithObject:[self.aMutableArray objectAtIndex:0]]
其中 doSomethingWithObject
的参数在调用 undo
方法之前不会被计算。换句话说,我不希望参数是 aMutableArray
的当前第一个元素,而是 undo
时 aMutableArray
的第一个元素。
我应该查看 NSInvocation 或 NSMethodSignature 的特定部分吗?
与任何方法调用一样,这只是一个发生在何处的问题。如果您现在不想 [self.aMutableArray objectAtIndex:0]
求值,请不要将其包含在调用表达式中!相反,使调用表达式成为对方法的调用,其中 该方法 将调用 [self.aMutableArray objectAtIndex:0]
:
[[self.undoManager prepareWithInvocationTarget:self]
doSomethingWithObjectAtIndex:0];
...其中 doSomethingWithObjectAtIndex:
是调用 [self.aMutableArray objectAtIndex:0]
的地方。
我正在尝试使用 NSUndoManager 的 prepareWithInvocationTarget。我想要像
这样的东西[[self.undoManager prepareWithInvocationTarget:self] doSomethingWithObject:[self.aMutableArray objectAtIndex:0]]
其中 doSomethingWithObject
的参数在调用 undo
方法之前不会被计算。换句话说,我不希望参数是 aMutableArray
的当前第一个元素,而是 undo
时 aMutableArray
的第一个元素。
我应该查看 NSInvocation 或 NSMethodSignature 的特定部分吗?
与任何方法调用一样,这只是一个发生在何处的问题。如果您现在不想 [self.aMutableArray objectAtIndex:0]
求值,请不要将其包含在调用表达式中!相反,使调用表达式成为对方法的调用,其中 该方法 将调用 [self.aMutableArray objectAtIndex:0]
:
[[self.undoManager prepareWithInvocationTarget:self]
doSomethingWithObjectAtIndex:0];
...其中 doSomethingWithObjectAtIndex:
是调用 [self.aMutableArray objectAtIndex:0]
的地方。