Skip to content

Instantly share code, notes, and snippets.

@mdb1
Last active September 12, 2023 20:39
Show Gist options
  • Select an option

  • Save mdb1/12886166dddb7b3b97fc8839fa7dbad4 to your computer and use it in GitHub Desktop.

Select an option

Save mdb1/12886166dddb7b3b97fc8839fa7dbad4 to your computer and use it in GitHub Desktop.
Xcode Template - ViewModel
//___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