Problem Context:
- SwiftUI/Combine
- Implementation based on RealmItems sample code
Problem:
struct SyncGroupsPage: View {
...
@ObservedObject var repository = SyncGroupRepository.shared
...
var body: some View {
...
Button(action: { _ = repository.addSyncGroupToCollection(name: "syncGroup=\(String.random(10))") }) ...
}
}
Repository:
class SyncGroupRepository: ObservableObject {
...
@Published var syncGroups: RealmSwift.List<SyncGroup>?
func addSyncGroupToCollection(name: String) -> SyncGroup {
let syncGroup = SyncGroup(name: name)
try! state.user?.realm?.write {
self.syncGroups?.append(syncGroup)
}
return syncGroup
}
...
}
Persistence is working as expected and if I leave the SyncGroupsPage view and come back in I see the updated values rendered.
syncGroups in the repository aren’t publishing any events when an append occurs. How should I modify the pattern?