gpt4 book ai didi

ios - 扩展 UIApplicationDelegate 协议(protocol)

转载 作者:搜寻专家 更新时间:2023-11-01 05:44:09 26 4
gpt4 key购买 nike

我想扩展 UIApplicationDelegate 协议(protocol)并为 application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 方法提供默认实现.但是,我提供的默认实现不会被调用。

是否有可能扩展 UIApplicationDelegate 协议(protocol)(关于 UIApplication 是单例,或者协议(protocol)方法是可选的),或者我做错了什么?

谢谢

AppDelegate.swift:

import UIKit
extension UIApplicationDelegate{
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
print("does not print anything on launch.")
return true
}
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
}

最佳答案

事实证明,您无法通过扩展为 Objective-C 协议(protocol)提供默认实现。有关协议(protocol)扩展限制的详细列表,请参见下面的链接。

https://www.captechconsulting.com/blogs/ios-9-tutorial-series-protocol-oriented-programming-with-uikit

What we CAN'T do: Provide default implementations for Objective-C protocols.

关于ios - 扩展 UIApplicationDelegate 协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36282835/

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