1.Form
A container for grouping controls used for data entry, such as in settings or inspectors.
对用于数据输入的控件(如设置或检查器)进行分组的容器
用法:
var body: some View {
Form {
Section(header: Text("Notifications")) {
Picker("Notify Me About", selection: $notifyMeAbout) {
Text("Direct Messages").tag(NotifyMeAboutType.directMessages)
Text("Mentions").tag(NotifyMeAboutType.mentions)
Text("Anything").tag(NotifyMeAboutType.anything)
}
Toggle("Play notification sounds", isOn: $playNotificationSounds)
Toggle("Send read receipts", isOn: $sendReadReceipts)
}
Section(header: Text("User Profiles")) {
Picker("Profile Image Size", selection: $profileImageSize) {
Text("Large").tag(ProfileImageSize.large)
Text("Medium").tag(ProfileImageSize.medium)
Text("Small").tag(ProfileImageSize.small)
}
Button("Clear Image Cache") {}
}
}
}
2.Future
A publisher that eventually produces a single value and then finishes or fails.
最终生成单个值,之后成功或失败 的 发布者
Future.Promise
A type that represents a closure to invoke in the future, when an element or error is available.、当元素或错误可用时,表示将来要调用的闭包 的类型
typealias Promise = (Result<Output, Failure>) -> Void
3.eraseToAnyPublisher()
用来将类型擦除,最后得到一个AnyPublisher类型的发布者
func eraseToAnyPublisher() -> AnyPublisher<Self.Output, Self.Failure>
二、报错问题记录
1.Cannot infer key path type from context; consider explicitly specifying a root type
Insert '<#Root#>'
ContentView().environment(\.managedObjectContext, persistenceController.container.viewContext)
Cannot find 'NSEntityDescription' and 'NSManagedObject' in scope
init(context: NSManagedObjectContext = PersistenceController.shared.container.viewContext) {
_viewModel = StateObject(wrappedValue: TodoViewModel(context: context))
}
解决办法 import CoreData
本文介绍SwiftUI中Form的使用方法及其在数据输入控件中的应用,并探讨Future模式如何实现异步操作及结果处理。
1707

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



