24. November 2016
Localized String constants
Another possibility for providing String
constants is via an extension on the String
type itself. This way it is even possible to automatically use the correct localized version of the string.
extension String {
private static func localized(key: String) -> String {
return NSLocalizedString(key, comment: "")
}
static var cancel = "Cancel"
static var save = String.localized(key: "save")
}
let cancel: String = .cancel
let save: String = .save
Via Swifting.