Get struct attribute by name(string) in Swift

Hi, I was wondering if there is something similar to NSObject's value(forKey:) for structs. I need to get a structs attribute by name and I don't want to turn my structs into classes, inherit from NSObject and use @objc in my attributes as I think it doesn't look good.

I also read that you can use Mirror and use the children property to iterate the attributes but given that performance is important in my case it doesn't look like a good option.

Any help would be appreciated, thanks!

No, there's nothing other than Mirror that will give you properties by name. A partial alternative might be to use key paths instead:

https://docs.swift.org/swift-book/ReferenceManual/Expressions.html

under the heading "Key-Path Expression".

Get struct attribute by name(string) in Swift
 
 
Q