2 Star 23 Fork 10

小弟调调/swiftui-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
.idoc
assets
example
accessibility
advanced-state
alerts-and-menus
animation
appendix-a
demo1
demo10
demo11
demo12
demo13
demo14
demo15
README.md
demo2
demo3
demo4
demo5
demo6
demo7
demo8
demo9
composing-views
containers
cross-platform
data
drawing
forms
images-shapes-media
introduction
lists
presenting-views
quick-start
responding-to-events
stacks-grids-scrollviews
taps-and-gestures
tooling
transforming-views
user-interface-controls
view-layout
working-with-static-text
cheat-sheet.md
.gitattributes
.gitignore
LICENSE
README.md
idoc.chapters.yml
idoc.yml
package.json
renovate.json
克隆/下载
README.md 1.08 KB
一键复制 编辑 原始数据 按行查看 历史

什么是 @UIApplicationDelegateAdaptor 属性包装器?

如果需要访问 SwiftUI 中的 AppDelegate 功能,则应创建一个继承自 NSObjectUIApplicationDelegate 的类,并为其提供所需的任何功能,例如:

class AppDelegate: NSObject, UIApplicationDelegate {
    // add app delegate methods here
}

例如,如果您想实现旧的 didFinishLaunchingWithOptions 方法,则可以使用以下方法:

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        print("Your code here")
        return true
    }
}

一旦有了,在主应用程序中使用 UIApplicationDelegateAdaptor 属性包装器,以便 SwiftUI 知道创建和管理您的应用程序委托类:

@main
struct NewIn14App: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Swift
1
https://gitee.com/jaywcjlove/swiftui-example.git
git@gitee.com:jaywcjlove/swiftui-example.git
jaywcjlove
swiftui-example
swiftui-example
main

搜索帮助