Last active
December 12, 2021 10:34
-
-
Save michzio/133dca25097ec836687acca68ff85bdb to your computer and use it in GitHub Desktop.
SwiftUI MVVM architecture - View
This file contains hidden or 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 WordsetCategoriesView<VM: WordsetCategoriesViewModelProtocol>: View { | |
// MARK: - View Model | |
@StateObject private var viewModel: VM | |
// MARK: - Core Data | |
@FetchRequest private var categories: FetchResults<WordsetCategory> | |
init(viewModel: VM) { | |
_viewModel = viewModel | |
_categories = FetchRequest( | |
entity: WordsetCategory.entity(), | |
sortDescriptors: [ | |
NSSortDescriptor(key: "foreignName", ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:))) | |
] | |
) | |
} | |
var body: some View { | |
List { | |
ForEach(Array(categories.enumerated()), id: \.1) { i, category in | |
Text("\(category.foreignName)") | |
} | |
} | |
.onAppear { | |
viewModel.syncWordsetCategories() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment