8000 GitHub - chunta/SwiftUIToDo
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chunta/SwiftUIToDo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

struct ToDoListView<ViewModel: ToDoViewModelProtocol>: View {
    @StateObject private var viewModel: ViewModel

    init(viewModel: ViewModel) {
        _viewModel = StateObject(wrappedValue: viewModel)
    }

這邊使用泛型,是因為可以讓編譯器在編譯時間檢查我們帶入的具體物件是否符合ToDoViewModelProtocol與是否為ObservableObject
如果是使用@StateObject private var viewModel: any ToDoViewModelProtocol時,由於protocol本身無法storage property, ex @Published,
必須runtime才能決定 由於這種不確定性 所以編譯器會報錯

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0