Hello,
I am working on a project whose model is generated automatically in Swift from a web (Typescript) representation, and contained in a library (say “Model”).
Each object from the model must be representable as a JSON dictionary, the properties being primitive types or basic structs (i.e., ParseGeoPoint is represented as a “ModelGeoPoint” struct containing a latitude and a longitude Doubles, and ParseFile corresponds to a “ModelFile” type, contains two String properties: url and name).
Hence, Parse is not used in this library. As an example:
protocol MissionClass {
var className: String { get }
var state: [String: Any] { get }
}
struct Player: MissionClass {
static var className: String {
return "Player"
}
var state: [String: Any] = [:]
var name: String? {
set { data["name"] = newValue }
get { data["name"] as? String }
}
var score: Double? {
set { data["score"] = newValue }
get { data["score"] as? Double }
}
// ...
}
With the legacy library (Parse-SDK-iOS), from the consumer app which uses the “Model” library, I could easily create a generic query which would only need the className from the associated object, and in the callback result, convert the properties (i.e., PFGeoPoint to ModelGeoPoint), in order to create the JSON dictionary as expected and fill the Redux state.
Now, I would like to replace the use of Parse-SDK-iOS for Parse-Swift, but I end up being stuck by the fact that this library seems to be more strongly typed. Admitting that I have a “Player” type into the “Model” library, I wouldn’t like to have to create a supplementary “Player” type into the consumer app, specifically to inherit ParseObject, because I would feel like having almost duplicate code.
What ideas could you suggest me?
Thank you for your help.