Yesterday I tried whether I can use dynamic properties with String-based enums (does not work). If the following code would work a lot of boilerplate could be avoided for a exact set of functions known at compile-time:
class Token {
enum DoubleGroup: String { case expiresAfter, ... }
enum StringGroup: String { case issuer, ... }
subscript(dynamicMember member: DoubleGroup) -> Double? { ... }
subscript(dynamicMember member: StringGroup) -> String? { ... }
}
Of course the type checker should be able to disambiguate the following code:
let exp = token.expiresAfter // -> Double?
let iss = token.issuer // -> String?