2

Now that in Xcode (8.3b3), using Swift 3.1, there’s a new compiler warning saying that the method initialize() will be disallowed in future versions, there is an alternative for method swizzling?

Alessandro
  • 686
  • 12
  • 19
  • You could write the swizzling code in Objective-C? – matt Feb 28 '17 at 20:38
  • 1
    You can still swizzle in Swift, but Swift offers no way to execute code automatically, when a class is loaded. So you have to initiate the swizzling explicitly, somewhere (unless you mix with Objective-C as matt suggested). – Martin R Feb 28 '17 at 20:51
  • Compare http://stackoverflow.com/questions/28422468/method-load-defines-objective-c-class-method-load-which-is-not-permitted-by. – Martin R Feb 28 '17 at 20:58

1 Answers1

0

Implement method swizzling in the app delegate Instead of adding method swizzling via a class extension, simply add a method to the app delegate to be executed when application(_:didFinishLaunchingWithOptions:) is called. Depending on the classes you’re modifying, this may be sufficient and should guarantee your code is executed every time.

Source: NsHipster

Lefteris
  • 14,550
  • 2
  • 56
  • 95
  • This approach won't work for classes initialized during an Application Extension execution context, as `AppDelegate`'s methods are not called in this case. – Yevhen Dubinin Mar 30 '17 at 16:32