Thursday, August 10, 2017 [Tweets] [Favorites]

Mixing Constant and Literal Strings in Swift

Joshua Emmons:

And now we have an interesting decision to make. Do we want to enforce safe, well-known constants and provide an option to specify arbitrary strings? Or do we want to allow arbitrary strings and provide an option to specify safe, well-known constants?

[…]

Situations come up all the time where we need an “escape hatch” from our carefully calculated set of pre-defined options.

When that happens, we don't need to throw our hands up in despair and make everything a String. Enumerations (combined with CustomStringConvertible and maybe even ExpressibleByStringLiteral) let us work around the 20% case while not jeopardizing the safety and convenience of the 80% out there.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment