Created
October 9, 2018 11:27
-
-
Save damijanracel/d4951ffada17ff575cd75ed9a7b6be47 to your computer and use it in GitHub Desktop.
UILabel extension for localization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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