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
public enum HttpMethod: String { | |
case options = "OPTIONS" | |
case get = "GET" | |
case head = "HEAD" | |
case post = "POST" | |
case put = "PUT" | |
case patch = "PATCH" | |
case delete = "DELETE" | |
case trace = "TRACE" | |
case connect = "CONNECT" |
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
func localized() -> String { | |
let localizedString = NSLocalizedString(self, comment: "") | |
return localizedString | |
} |
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
enum LocalizationKey: String { | |
case hello = "hello" | |
case bye = "bye" | |
case progress = "progress" | |
var string: String { | |
return rawValue.localized() | |
} | |
} |
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
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): |
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
class LocalizedLabel: UILabel { | |
var localizationKey: LocalizationKey? | |
func set(key: LocalizationKey) { | |
localizationKey = key | |
text = key.string | |
} | |
} |
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" | |
} |
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
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)) | |
} |
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
"hello" = "hello"; | |
"bye" = "bye %@"; | |
"progress" = "Finished %d of %d"; |
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
class LocalizedLabel: UILabel { | |
var localizationKey: LocalizationKey? | |
func set(key localization: Localization) { | |
self.text = localization.string | |
self.localizationKey = localization.key | |
} | |
} |
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
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 { |