You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
I have a use case where there can be multiple datasources accessed through a strategy pattern. Those strategies return similar objects (json from the network).
Internally they handle the data differently and can't share the same data model, but for the functionality using those API's this doesn't really matter.
I'd like to "proxy" the data behind some protocol which is backed by the JSON data itself. Is there a good pattern for that?
I'll share an example:
protocol EventType {
associatedtype PointType: DataPointType
var timestamp: Int {get}
var value: Double {get}
var data : PointType
}
protocol DataPointType {
var field1: Int {get}
var field2: String {get}
// etc. etc.
}
.... get some data as json ....
let jsonData: AnyCodable = .... get the data from somewhere .... there are many internal types and don't want to craft custom types for each one
// jsonData structure adheres to EventType ....
/// I need a concrete dynamic object conforming to the EventType
// some sort of generic object which implements the EventType protocol
let typedData = Proxy<EventType>(jsonData) // behave like the protocol with the backing jsonData and I don't want to create. a concrete type implementing EventType
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I have a use case where there can be multiple datasources accessed through a strategy pattern. Those strategies return similar objects (json from the network).
Internally they handle the data differently and can't share the same data model, but for the functionality using those API's this doesn't really matter.
I'd like to "proxy" the data behind some protocol which is backed by the JSON data itself. Is there a good pattern for that?
I'll share an example:
The text was updated successfully, but these errors were encountered: