我正在将Objective-C项目翻译成Swift。
我想在系统方法调用时执行自定义方法。
Objective-C中的代码:他使用了C-Type方法,混合方法。执行自定义方法并继续运行系统方法:
void dzn_original_implementation(id self, SEL _cmd)
{
// Fetch original implementation from lookup table
Class baseClass = dzn_baseClassToSwizzleForTarget(self);
NSString *key = dzn_implementationKey(baseClass, _cmd);
NSDictionary *swizzleInfo = [_impLookupTable objectForKey:key];
NSValue *impValue = [swizzleInfo valueForKey:DZNSwizzleInfoPointerKey];
IMP impPointer = [impValue pointerValue];
// We then inject the additional implementation for reloading the empty
// dataset
// Doing it before calling the original implementation does update the
// 'isEmptyDataSetVisible' flag on time.
[self dzn_reloadEmptyDataSet];
// If found, call original implementation
if (impPointer) {
((void(*)(id,SEL))impPointer)(self,_cmd);
}
}
我应该在Swift中做什么?如何从IMP?
执行方法这个函数不仅仅用于reloadData(),而且还用于endUpdate()!