SwiftUI开发实用指南
一、应用设置与部署
在开发过程中,应用的设置和部署是重要环节。我们可以通过以下代码来设置新闻URL源和内容:
newsURLSources.source =
UserDefaults.standard.string(forKey: "source")
?? "engadget"
newsURLSources.content =
UserDefaults.standard.string(forKey:
"content") ?? "top-headlines"
let contentView =
ContentView().environmentObject(newsURLSources)
// Use a UIHostingController as window root view
controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController =
UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
这样设置后,当对偏好设置进行更改时,更改会持久化存储。应用重启时,会加载上次保存的设置值。
接下来是将应用部署到iPhone的步骤
超级会员免费看
订阅专栏 解锁全文

895

被折叠的 条评论
为什么被折叠?



