iOS Platform & SwiftUI (50 Qs)•Part 2: Combine, Persistence, Security & Networking (11 - 24)
What is Method Swizzling and why is it dangerous in Swift?
junior LevelSecurity & Auth
In Simple Words: Method Swizzling uses the Objective-C runtime to swap the implementation of two methods at runtime:
- Often used by analytics SDKs (Firebase, New Relic) to automatically track screen views by swizzling
viewDidAppear. - Dangers: Breaks compiler type safety, introduces race conditions, causes unpredictable crashes across iOS version updates, and does not work on Swift methods using static dispatch.