swift - Access String value in enum without using rawValue -
i replace global string constants nested enum keys i'm using access columns in database.
the structure follows:
enum databasekeys { enum user: string { case table = "user" case username = "username" ... } ... }
each table in database inner enum, name of table being enum's title. first case in each enum name of table, , following cases columns in table.
to use this, it's pretty simple:
myuser[databasekeys.user.username.rawvalue] = "johnny"
but using these enums a lot. having append .rawvalue
every instance pain, , it's not readable i'd be. how can access string value without having use rawvalue
? it'd great if can this:
myuser[databasekeys.user.username] = "johnny"
note i'm using swift 2. if there's better way accomplish i'd love hear it!
while didn't find way using desired syntax enums, possible using structs.
struct databasekeys { struct user { static let identifier = "user" static let username = "username" } }
to use:
myuser[databasekeys.user.username] = "johnny"
apple uses structs storyboard , row type identifiers in watchkit templates.
Comments
Post a Comment