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 / Usage.swift
Last active October 16, 2018 07:39
Enum with parameters usage
label.text = LocalizationKey.progress(10, 1)
@damijanracel
damijanracel / LocalizationKeyEnumParameters.swift
Last active October 15, 2018 10:22
LocalizationKey enum with parameters
enum LocalizationKey {
case hello
case bye(String)
case progress(Int, Int)
var string: String {
switch self {
case .hello:
return "hello".localized()
case .bye(let name):
@damijanracel
damijanracel / LocalizationExample.swift
Created October 15, 2018 10:15
Localization example
“hello”.localized()
@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 / LocalizationKeyEnum.swift
Last active October 15, 2018 08:10
Localization key enum
enum LocalizationKey: String {
case hello = "hello"
case bye = "bye"
case progress = "progress"
var string: String {
return rawValue.localized()
}
}
@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
}
}