Objective-C プロジェクトを Swift に翻訳しています。
システムメソッドの呼び出し時にカスタムメソッドを実行したい。
Objective-C のコード: 彼は C タイプのメソッド、スウィズリング メソッドを使用しました。カスタム メソッドを実行し、システム メソッドの実行を続行します。
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() にも用意されています!