Created
August 18, 2019 23:58
-
-
Save PaulWoodIII/afd75bc9dcb61c9616e5877f63448e43 to your computer and use it in GitHub Desktop.
a quick hack on selected items in a list via @zoejessica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// OrderedList | |
// | |
// Created by Paul Wood on 8/18/19. | |
// Copyright © 2019 Paul Wood. All rights reserved. | |
// | |
import SwiftUI | |
import Combine | |
class Context: ObservableObject { | |
@Published var selectedIngrediants: Set<String> | |
@Published var ingrediants: Array<String> | |
init() { | |
self.ingrediants = ["A","B","C"] | |
self.selectedIngrediants = ["A"] | |
} | |
} | |
extension String: Identifiable { | |
public var id: String { return self } | |
} | |
struct Chooser : View { | |
@ObservedObject var context: Context | |
var body: some View { | |
NavigationView { | |
List (context.ingrediants, selection: $context.selectedIngrediants) { item in | |
Text(item) | |
}.environment(\.editMode, .constant(.active)) | |
} | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
Chooser(context: Context()) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment