0

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!

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Y.Kay
  • 31
  • 3
  • Look at this [SO post answer](https://stackoverflow.com/a/39562888/5546312) – D4ttatraya May 31 '17 at 15:54
  • Most of results online in not required. I wanner insert some code before system method, not exchange simply. And the main trouble is how to use the IMP I am holding to perform a method – Y.Kay Jun 01 '17 at 01:13

0 Answers0