0
extension UIApplication {

    override open var next: UIResponder? {
        print("next")
        return super.next
    }
}

上面的代码是在iOS 13.4之前执行的,在方法next之前打印了“ ”application(_:, didFinishLaunchingWithOptions:)

iOS 13.4和最新的iOS 13.4.1上,控制台不输出next。如果我print()在行上断了断点,断点将不会被执行

这导致我以前的一些代码失败,例如:

import UIKit

public extension UIApplication {

    private static let runOnce: Void = {
        NothingToSeeHere.harmlessFunction()
    }()

    override var next: UIResponder? {

        // Called before applicationDidFinishLaunching
        UIApplication.runOnce

        return super.next
    }
}

public protocol SelfAware: class {
    static func awake()
}

public class NothingToSeeHere {

    public static func harmlessFunction() {

        let typeCount = Int(objc_getClassList(nil, 0))
        let types = UnsafeMutablePointer<AnyClass>.allocate(capacity: typeCount)
        let autoreleasingTypes = AutoreleasingUnsafeMutablePointer<AnyClass>(types)

        objc_getClassList(autoreleasingTypes, Int32(typeCount))

        for index in 0 ..< typeCount {
            (types[index] as? SelfAware.Type)?.awake()
        }

        types.deallocate()
    }
}

为什么会这样?这是 iOS 13.4 中的错误吗?还是特色?我在 iOS 13.4 的发行说明中没有找到任何相关内容...


让我列出我测试的情况:

  • 13.2 iPhone、next方法执行和之前application(_:, didFinishLaunchingWithOptions:)的 .
  • 13.3 模拟器、next方法执行和之前application(_:, didFinishLaunchingWithOptions:)的 .
  • 13.4 模拟器,next方法未执行。
  • 13.4 iPhone,next方法未执行。
  • 13.4.1 iPhone,next方法未执行。
4

2 回答 2

1

Xcode 11.4 和 iOS 13.4 不再允许在扩展中覆盖 var,您是否有可能使用旧 Xcode 进行调试。如果您运行它但不调试它,则将调用该方法。

于 2020-04-16T04:38:54.817 回答
1

我也遇到过这个问题,但是我打开项目方案并取消选中调试可执行选项。覆盖方法可以运行。

于 2020-06-25T12:48:16.297 回答