-1

I have a method in ClassA which is called Selector1,

In ClassB I want to create a NSInvocation object and set the Selector1 as the object's selector. Is this possible? I don't know the proper way to set up this.

The code I am trying to use in ClassB is like this:

NSMethodSignature *signature = [ClassA methodSignatureForSelector:@selector(Selector1:)];
NSInvocation *invocationToPass = [NSInvocation invocationWithMethodSignature:signature];
invocationToPass.target = self;
invocationToPass.selector = Selector1; // How can I assign Selector1 from ClassA?
newguy
  • 5,668
  • 12
  • 55
  • 95

1 Answers1

1

You need a SEL, just like the one you passed to methodSignatureForSelector:, not just the name of the method.

[invocationToPass setSelector:@selector(Selector1:)];

You also need to be aware that the colon is significant. If the method takes no arguments, then the name will be Selector1; if it takes one, the name is Selector:. You need to put the correct name into the @selector() operator.

jscs
  • 63,694
  • 13
  • 151
  • 195