> On 10 May 2015, at 11:07 pm, Charles Jenkins <cejw...@gmail.com> wrote:
> 
> Am I correct to believe there is NO way to use 
> NSUndoManager.prepareWithInvocationTarget: if your undo method requires a 
> parameter?


No, that’s not correct.

This approach allows you to pass any method signature whatsoever, because the 
return type of -prepareWithInvocationTarget: is an id, and the object it 
represents accepts any method signature. It’s much MORE flexible than 
-registerUndoWithTarget:selector:object, which allows you to pass exactly one 
parameter, which must be an object (or no parameters and nil).

What NSUndoManager does internally when you use prepareWithInvocationTarget is 
to wrap whatever you pass with an NSInvocation - so understanding that class is 
useful to also understand NSUndoManager.

> I can use any method I want which has no parameter, but any method with 
> parameters gets me the error “AnyObject does not have member named…”

I’m not sure exactly why that’s happening - maybe post your code that’s causing 
this and the problem might be clear. But it may be because using 
-prepareWithInvocationTarget as if it were a property is incorrect - it’s not a 
property so it shouldn’t be treated as one (I realise that the way properties 
are implemented is supposed to be exactly equivalent to a method call, but 
there are cases where they are semantically different and this is likely one of 
them. -prepareWithInvocationTarget: is kind of tricksy. For clarity, you should 
probably only write code that uses the dot syntax strictly for properties, and 
uses classic bracket syntax for other methods. The intention of your code will 
be clearer, and you will likely avoid these kinds of issues).

—Graham



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to