2016-09-28 44 views
1

遇到麻煩的代碼轉換下方夫特3語法:缺少「」分隔符後夫特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 ',' separatorclass_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:)))。我在這裏做錯了什麼?

回答

1

遷移工具並不總是完美的。只要將第一行看起來像第二行,但沒有前綴EA_即可。更改

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

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

等等...

+0

這篇和錯誤已經走了,但現在每第二行有'預期「」 separator'錯誤 – Kex

+0

@馬特我想你在''之前需要另一個圓括號,' –

+0

這樣做!謝謝! – Kex