具有后台任务的 SwiftUI 架构
我正在编写我的第一个 SwiftUI 应用程序,它需要在后台执行各种任务;例如偶尔从 API 获取数据、响应 Web 套接字事件等。
我的问题是,启动此类后台任务的最佳位置在哪里?一种想法是任务块挂在 WindowGroup 上,但我确实没有正确的线索。任何人都可以推荐有关 SeiftUI 应用程序架构的资源吗?我正在遵循 MVI 模式。
I am writing my first SwiftUI app which needs to be performing various tasks in the background; such as occasionally fetching data from an API, responding to web socket events, stuff like that.
My question is, where is the best place to kick off such background tasks? One thought is Task block hanging off the WindowGroup
but I really have no proper clue. Any resources anyone can recommend about the architecture of SeiftUI apps? I’m following the MVI pattern.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在视图中使用新的
.task()
修饰符。这是异步下载图像的示例:You can use the new
.task()
modifier to the view. Here's an example of downloading an image asynchronously: