I've got a list of instances of the following struct called payment_list:
struct Payment: Codable {
let id: Int
let payment_hash: String
let destination: String
let msatoshi: Int
let timestamp: Int
let created_at: Int
let status: String
enum PaymentKeys: String, CodingKey {
case payments
}
}
I can access the members of each struct instance in the list in the following manner:
print(payment_list[0].id) // 1
print(payment_list[0].timestamp) // 1517083775
Is it possible to access those struct instance members using a variable to determine which member is being accessed? Something along the lines of:
var column = "id"
print(payment_list[0][column]) // 1
I've read about people using NSObject and value(forKey key: String), but this is a struct so it can't inherit from NSObject. If it was an object I think it would look something like this:
var column = "id"
print(payment_list[0].value(forKey key: column)) // 1
Is this type of thing possible with struct?