-
-
Save laevandus/9af8899f1e9d46aa07e7d5a30370c3d1 to your computer and use it in GitHub Desktop.
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
struct Fruit: Identifiable { | |
let id = UUID().uuidString | |
let name: String | |
} | |
final class ViewModel: ObservableObject { | |
init(fruits: [Fruit] = ViewModel.defaultFruits) { | |
self.fruits = fruits | |
self.selectedId = fruits[1].id | |
} | |
@Published var fruits: [Fruit] | |
@Published var selectedId: String? | |
static let defaultFruits: [Fruit] = ["Apple", "Orange", "Pear"].map({ Fruit(name: $0) }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment