XCODE passes the method as a parameter

I will not pass the method as a parameter to another method, so it knows the method to call when shutting down. Is it possible?

[self bringJSON:(NSString *)_passedValua:(NSObject *)anotherMethod]; 
+4
source share
1 answer

As @Daniel mentioned in the comments, you can use selector . The basic scheme will be as follows:

 // 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]; } 
+15
source

Source: https://habr.com/ru/post/1415941/


All Articles