gpt4 book ai didi

ios - 方法 swizzle 的 Swift 3 迁移后缺少 ',' 分隔符

转载 作者:行者123 更新时间:2023-11-28 06:33:08 25 4
gpt4 key购买 nike

我在将以下代码转换为 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 for class_getClassMethod(self, #selector(UIView.animate(withDuration:animations:)(_:animations: )))。我在这里做错了什么?

最佳答案

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

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

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

等等……

关于ios - 方法 swizzle 的 Swift 3 迁移后缺少 ',' 分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39753309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com