Method originalMethod = class_getInstanceMethod([Animal class], selector); Method swizzledMethod = class_getInstanceMethod([Plant class], selector); method_exchangeImplementations(originalMethod, swizzledMethod); // ObjC NSLog(@"I am %@!", name); // I am Plant! // Swift print("I am \(name)!") // I am Animal!
Method originalMethod = class_getInstanceMethod([Animal class], selector); Method swizzledMethod = class_getInstanceMethod([Plant class], selector); method_exchangeImplementations(originalMethod, swizzledMethod); // ObjC NSLog(@"I am %@!", name); // I am Plant! // Swift print("I am \(name)!") // I am Plant!