我无法将下面的代码转换为Swift 3语法:
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:))))
}
}
上面的代码是在运行迁移工具之后。例如,我最初有:
method_exchangeImplementations(
class_getClassMethod(self, #selector(UIView.animateWithDuration(_:animations:))),
class_getClassMethod(self, #selector(UIView.EA_animateWithDuration(_:animations:))))
但现在在第二行,我收到Expected ',' separator
的错误class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:)))
。我在这里做错了什么?
答案 0 :(得分:1)
迁移工具并不总是完美的。只需使第一行看起来像第二行但没有EA_
前缀。变化
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:))),
到
class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:))),
依旧......