How can I create a more detailed array with objects | Swift
Solution 1:
You can use a struct
that conforms to Codable
to represent your data:
struct Model : Codable, Hashable {
var myexample: String
var id: Int
}
var mySet = Set([Model(myexample: "Example2", id: 1),
Model(myexample: "Example3", id: 2)])
mySet.insert(Model(myexample: "Example4", id: 3))
do {
let json = try JSONEncoder().encode(mySet)
print(String(data: json, encoding: .utf8)!)
} catch {
print(error)
}