就像标题说的:我有一个 ObjcClass 我想要一些东西可以被重用,因为这个类可能有
-(void)test1:xxx -(void)test2:xxx argu:yyy
我不想那样做
[dispatchArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj test2:xxx argu:yyy];
}];
例子:
- (void)test:(NSString *)argument1 {
NSArray *dispatchArray = @[];//If the array is initialized with multiple objects
//I want each object to call the "test:" method unlike the following
// [dispatchArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// [obj performSelector:@selector(test:) withObject:argument1];
// // or [obj test:argument1];
// }];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[_services enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * stop) {
if ([obj respondsToSelector:_cmd]) {
[obj application:application didFinishLaunchingWithOptions:launchOptions];
}
}];
return YES;
}
像这样,UIApplicationDelegate 有很多方法,我不想写 [obj application:application didFinishLaunchingWithOptions:launchOptions]; 或[obj applicationWillResignActive:application]; 在每个方法中,相反我希望像[obj respondsToSelector:_cmd]这样的方法,我可以提出像[obj invokeWithMethod:_cmd arguments:_VA_LIST] 这样的通用方法; 这些方法是否可以优化,因为它们对不同的方法做同样的事情