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 ',' separator
爲class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations:)))
。我在這裏做錯了什麼?
這篇和錯誤已經走了,但現在每第二行有'預期「」 separator'錯誤 – Kex
@馬特我想你在''之前需要另一個圓括號,' –
這樣做!謝謝! – Kex