Kex Kex - 2 months ago 20
Swift Question

Missing ',' separator after Swift 3 migration for method swizzle

I'm having trouble converting the code below to Swift 3 syntax:

extension UIView {


override public static func initialize() {
if !didEAInitialize {
replaceAnimationMethods()
didEAInitialize = true
}
}

private static func replaceAnimationMethods() {
//replace actionForLayer...
method_exchangeImplementations(
class_getInstanceMethod(self, #selector(UIView.actionForLayer(_:forKey:))),
class_getInstanceMethod(self, #selector(UIView.EA_actionForLayer(_:forKey:))))

//replace animateWithDuration...
method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:))))
method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:completion:)(_:animations:completion:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:completion:))))
method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animate(withDuration:delay:options:animations:completion:)(_:delay:options:animations:completion:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:delay:options:animations:completion:))))
method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animate(withDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:))))

}

}


The code above is after running the migration tool. For example I originally had:

method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animateWithDuration(_:animations:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:))))


But now on the second line I get the error
Expected ',' separator
for
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:)))
. What am I doing wrong here?

Answer

The migration tool is not always perfect. Just make the first line look like the second line but without the EA_ prefix. Change

class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:))),

to

class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)),

and so on...

Comments