If your AppDelegate is written in Objective-C and you are looking to write an extension to support Swift, this article is for you..
如果您的AppDelegate是用Objective-C编写的,并且您正在寻找写扩展以支持Swift,那么本文适合您。
Create a new swift file — example, AppDelegateExtension.swift , and add the following code snippet.
创建一个新的swift文件—例如AppDelegateExtension.swift ,并添加以下代码片段。
AppDelegateExtension.swift AppDelegateExtension.swiftNote: Don’t forget to include public access specifier, else methods inside extension cannot be accessed in Objective-C file.
注意:不要忘了包括公共访问说明符,否则在Objective-C文件中不能访问扩展内部的方法。
In your AppDelegate.m, you can call extension methods. See the below code snippet
在您的AppDelegate.m中,您可以调用扩展方法。 参见下面的代码片段
AppDelegate.m AppDelegate.mIn your AppDelegate.m, add the following header.
在您的AppDelegate.m中,添加以下标头。
import "Objective C generated Interface Header Name"You can get this value from: Build Settings -> Swift Compiler General
您可以从以下位置获取此值: Build Settings-> Swift Compiler General
That’s it folks.. hope you like this. :)
就是这样..希望你喜欢这个。 :)
翻译自: https://medium.com/macoclock/extend-appdelegate-from-objective-c-to-swift-e0b4127c30d1