Hi. I want to create a data layer that can be agnostic to the rest of the app because I need to be able to switch data providers.
I know it’s not the primary design, that I can “lose” some features, etc. But everything depends on the capacity of doing this, it’s either this way or not realm at all for my company.
Now, to the point. I have worked on it for a while and have it mostly working, but I want to understand one part that I still can’t achieve.
I have this function:
func subscribe<T: Object>(name: String, model: T) async throws {
guard let realm = realm else { throw DataManagerError.DataSourceError }
let subscriptions = realm.subscriptions
let subsc = QuerySubscription<model>(name: name)
try await subscriptions.update {
subscriptions.append(
subsc
)
}
}
Which is just the base for a simple general subscription function. Nothing isolated yet, but it’s a start. My problem comes with the QuerySubscription<model>(name: name)
because it says it can’t find type model in scope. Is there any way I can do this without specifying the model class here?
I guess this could also apply for something I need. Let’s say I have a list of data models I may want to subscribe to. Do I really need to duplicate subscription code for each object model, each using its own class? This function could work there too.
Thanks