iOS中方法作为属性或者是参数进行传递,下边我是以代理方法为例。
.h中的代码让代理方法作为一个属性
@property(nonatomic,assign)SEL delegateSelect;
.m中的代码让delegate调用这个传过来的代理方法 传值用withObject:一个对象传递
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)
if ([self.delegate respondsToSelector:self.delegateSelect]) {
NSMutableDictionary* dict = [[NSMutableDictionary alloc] init];
[dict setValue:[NSNumber numberWithFloat:oldCoordinate.longitude] forKey:@"longitude"];
[dict setValue:[NSNumber numberWithFloat:oldCoordinate.latitude] forKey:@"latitude"];
SuppressPerformSelectorLeakWarning([self.delegate performSelector:self.delegateSelect withObject:place.name withObject:dict]);
}