I have a JSON filled with a list of Vendors. Whats the best and most efficient way of holding this as instances that are easily accessible within the class and passable through the project. I was thinking of using struct as i haven't used them before. Is it better than using Object?
Below i have my Struct.
struct Vendor {
let name: String
let latitude: Double
let longitude: Double
init(dictionary: [String: Any]) {
self.name = dictionary["name"] as? String ?? ""
self.latitude = dictionary["Lat"] as? Double ?? 0.0
self.longitude = dictionary["Lng"] as? Double ?? 0.0
}
init?(data: Data) {
guard let json = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any] else { return nil }
self.init(dictionary: json)
}
init?(json: String) {
self.init(data: Data(json.utf8))
}
}
My question is how would i create an Array from the JSON of this struct type.
Thanks