-
-
Save laevandus/827e998eb5be84568c4a64bd2abdd0cd 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
import SwiftUI | |
struct ContentView: View { | |
@StateObject var viewModel = ViewModel() | |
var body: some View { | |
VStack { | |
ForEach(viewModel.items) { item in | |
Text(verbatim: item.name) | |
} | |
} | |
.padding() | |
} | |
} | |
extension ContentView { | |
final class ViewModel: ObservableObject { | |
let items: [Item] = [ | |
Item(name: "first"), | |
Item(name: "second") | |
] | |
func select(_ item: Item) { | |
// implement | |
} | |
} | |
struct Item: Identifiable { | |
let name: String | |
var id: String { name } | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment