Last active
September 12, 2023 20:39
-
-
Save mdb1/12886166dddb7b3b97fc8839fa7dbad4 to your computer and use it in GitHub Desktop.
Xcode Template - ViewModel
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
| //___FILEHEADER___ | |
| import Foundation | |
| extension ___VARIABLE_ViewName___ { | |
| final class ViewModel: ObservableObject { | |
| private let dependencies: Dependencies | |
| init(dependencies: Dependencies = .default) { | |
| self.dependencies = dependencies | |
| } | |
| } | |
| } | |
| extension ___VARIABLE_ViewName___.ViewModel { | |
| struct Dependencies { | |
| // TODO: Add dependencies here | |
| var doSomething: () async throws -> Void | |
| static var `default`: Self { | |
| .init { | |
| // TODO: Provide the default dependencies here | |
| return | |
| } | |
| } | |
| } | |
| } | |
| extension ___VARIABLE_ViewName___.ViewModel { | |
| // TODO: Replace me | |
| @MainActor | |
| func doSomething() async { | |
| do { | |
| try await dependencies.doSomething() | |
| } catch { | |
| // Error handling | |
| } | |
| } | |
| } | |
| private extension ___VARIABLE_ViewName___.ViewModel { | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment