0

它工作得很好,除了信息在下次启动之前不会更新。

struct LoveFamilyAndFriendsView: View {
@State private var selectedStatus = NSUbiquitousKeyValueStore.default.string(forKey: "selectedStatus") ?? ""
var body: some View {
    VStack {
        Form {
            List {
                Picker("Status", selection: $selectedStatus) {
                    Text("Married").tag("Married")
                    Text("Divorced").tag("Divorced")
                    Text("Single").tag("Single")
                    Text("Dating somebody").tag("Dating somebody")
                }.onChange(of: selectedStatus, perform: { value in
                    NSUbiquitousKeyValueStore.default.set(value, forKey: "selectedStatus")
                    selectedStatus = NSUbiquitousKeyValueStore.default.string(forKey: "selectedStatus") ?? ""
                })
            }
        }
    }.navigationTitle("Love, Family and Friends")
}

}

4

0 回答 0