I have a struct with a protocol like,
protocol Page {
func getAllProperties () -> [String: Any]
}
extension Page {
public func getAllProperties () -> [String: Any] {
var result: [String: Any] = [:]
let mirror = Mirror(reflecting: self)
print(mirror)
for (labelMaybe, valueMaybe) in mirror.children {
print(labelMaybe)
guard let label = labelMaybe else {
continue
}
result[label] = valueMaybe
}
return result
}
}
struct Test: Page {
static let aa = "aaaaa"
let bb = "bbbb"
}
Here Test().getAllProperties()
returns only bb
, it omits the static
property!!!
I want that getAllProperties()
return those static property too!
is there any way for it?
To the best of my knowledge, the answer is no. Sorry. Even getting a Mirror
on the type(of: self)
doesn't end up having any children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With