在方法混合的Swift 3迁移之后缺少','分隔符

时间:2016-09-28 16:46:15

标签: ios swift swift3

我无法将下面的代码转换为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:)))。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

迁移工具并不总是完美的。只需使第一行看起来像第二行但没有EA_前缀。变化

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

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

依旧......