Reputation: 31
I'm translating an Objective-C project to Swift.
I want to perform custom method when a system method is calling.
Code in Objective-C: He used a C-Type method, swizzling method. perform custom method and continue running system method:
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);
}
}
What should I do in Swift? How to perform method form it's IMP?
And this func isn't prepared for reloadData() only, but endUpdate() either!
Upvotes: 0
Views: 80