4

I wan't to pass a method as a parameter to another method, so it know the method to call when ends running. Is it possible?

[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod]; 
1
  • Have you tried using selectors? Commented Jun 4, 2012 at 11:18

1 Answer 1

15

As @Daniel mentioned in comments you can use selector for that. Basic scheme will be the following:

// Method declaration - method accept selector as parameter - (void) bringJSON:(NSString *)_passedValua toMethod:(SEL)anotherMethod]; // Method call - create selector from method name (mind the colon in selector - it is required if your method takes 1 parameter) [self bringJSON:jsonString toMethod:@selector(methodName:)]; // Implementation - (void) bringJSON:(NSString *)_passedValua toMethod:(SEL)anotherMethod]{ ... if ([target respondsToSelector:anotherMethod]) [target performSelector:anotherMethod withObject:_passedValua]; } 
Sign up to request clarification or add additional context in comments.

2 Comments

awsome! tks a lot Vladimir and Daniel!
nice, honourable... thanx buddy :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.