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>

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐