Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am damijanracel on github.
  • I am maishu (https://keybase.io/maishu) on keybase.
  • I have a public key ASCmxxCQDHnV-oY5wDvy6YI__vkzajzNbHQKrJaVbcFa_Ao

To claim this, I am signing this object:

@damijanracel
damijanracel / FormatSpecifiers.swift
Last active October 16, 2018 07:39
Localization with format specifiers
label.text = String(format: LocalizationKey.bye.string, name)
@damijanracel
damijanracel / LocalizationExample.swift
Created October 15, 2018 10:15
Localization example
“hello”.localized()
@damijanracel
damijanracel / Usage.swift
Last active October 16, 2018 07:39
Enum with parameters usage
label.text = LocalizationKey.progress(10, 1)
@damijanracel
damijanracel / TestingLocalization.swift
Created October 11, 2018 14:44
Testing localization example
func testLabel_Should_SetCorrectLocalizationKey() {
XCTAssertEqual(mainViewController!.label.localizationKey, LocalizationKey.bye)
}
@damijanracel
damijanracel / LocalizationStruct.swift
Created October 11, 2018 14:40
Localization struct upgrade
struct Localization {
let key: LocalizationKey
let string: String
private init(string: String, key: LocalizationKey) {
self.string = string
self.key = key
}
static func bye(name: String) -> Localization {
@damijanracel
damijanracel / LocalizedLabel.swift
Created October 11, 2018 14:37
Localized label for struct
class LocalizedLabel: UILabel {
var localizationKey: LocalizationKey?
func set(key localization: Localization) {
self.text = localization.string
self.localizationKey = localization.key
}
}
@damijanracel
damijanracel / Localizable.string
Created October 11, 2018 14:07
Localizable strings
"hello" = "hello";
"bye" = "bye %@";
"progress" = "Finished %d of %d";
@damijanracel
damijanracel / LocalizationStruct.swift
Last active October 15, 2018 08:16
Localization struct
struct Localization {
let string: String
private init(string: String) {
self.string = string
}
static func bye(name: String) -> Localization {
return Localization(string: String(format: LocalizationKey.bye.string, name))
}
@damijanracel
damijanracel / UILabelLocalizationExtension.swift
Created October 9, 2018 11:27
UILabel extension for localization
extension UILabel {
func set(key: LocalizationKey) {
localizationKey = key
text = key.string
}
private struct AssociatedKeys {
static var localizationKey = "nsh_localizationKey"
}