Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UILabel extension for localization
extension UILabel {
func set(key: LocalizationKey) {
localizationKey = key
text = key.string
}
private struct AssociatedKeys {
static var localizationKey = "nsh_localizationKey"
}
var localizationKey: LocalizationKey? {
get {
return objc_getAssociatedObject(self, &AssociatedKeys.localizationKey) as? LocalizationKey
}
set {
if let newValue = newValue {
objc_setAssociatedObject(self, &AssociatedKeys.localizationKey, newValue as LocalizationKey?,
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.