Skip to content

Instantly share code, notes, and snippets.

@arrmixer
Last active October 9, 2023 19:18
Show Gist options
  • Save arrmixer/65b5476f8da1f8771566cc4eeb4e4fd2 to your computer and use it in GitHub Desktop.
Save arrmixer/65b5476f8da1f8771566cc4eeb4e4fd2 to your computer and use it in GitHub Desktop.
Shared ViewModel wrapper for swift
// create a new Observable object class to allow the views to observed usign the @StateObject annotation
final class RemindersViewModelWrapper: ObservableObject {
let viewModel = RemindersViewModel()
@Published private(set) var reminders: [Reminder] = [] // stream that the view will listen to within the Obeservable Object
init() {
viewModel.onRemindersUpdated = { [weak self] items in
self?.reminders = items
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment