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 NatureViewController: UIViewController { | |
@Localized(.natureTitle) | |
@IBOutlet private var label: UILabel! | |
@Localized(.saveNatureButton) | |
@IBOutlet private var button: UIButton! | |
} |
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 | |
natureTitle, | |
saveNatureButton | |
} | |
extension LocalizationKey { | |
var string: String { | |
NSLocalizedString(rawValue, comment: rawValue) | |
} |
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
protocol Localizable { | |
func set(localization: LocalizationKey) | |
} | |
extension UIButton: Localizable { | |
func set(localization key: LocalizationKey) { | |
setTitle(key.string, for: .normal) | |
} | |
} |
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
@propertyWrapper | |
struct Localized<T: Localizable> { | |
private let key: LocalizationKey | |
var wrappedValue: T? = nil { | |
didSet { | |
wrappedValue?.set(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
class NatureViewController: UIViewController { | |
@IBOutlet private var label: UILabel! { | |
didSet { | |
label.title = NSLocalizedString("natureTitle", comment: "") | |
} | |
} | |
@IBOutlet private var button: UIButton! { | |
didSet { | |
button.setTitle(NSLocalizedString("saveNatureButton", comment: ""), for: .normal) |
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 NatureViewController: UIViewController { | |
@Localized("natureTitle") | |
@IBOutlet private var label: UILabel! | |
@Localized("saveNatureButton") | |
@IBOutlet private var button: UIButton! | |
} |
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
// | |
// UIFont+.swift | |
// Autofriend | |
// | |
// Created by Pilipenko Dima on 10/9/17. | |
// Copyright © 2017 dimpiax. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
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
let decoder = JSONDecoder() | |
decoder.dateDecodingStrategy = .custom { decoder -> Date in | |
let valueContainer = try decoder.singleValueContainer() | |
let value = try valueContainer.decode(String.self) | |
if let regex = try? NSRegularExpression(pattern: "\\.\\d+", options: []) { | |
let result = regex.stringByReplacingMatches(in: value, options: [], range: NSRange(location: 0, length: value.count), withTemplate: "") | |
if let date = ISO8601DateFormatter().date(from: result) { | |
return date |
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
const next = async (it, callback) => { | |
const { value, done } = it.next() | |
if (done) return [] | |
const result = await callback(value) | |
const nextResult = await next(it, callback) | |
return [result, ...nextResult] | |
} | |
const sync = async (value, callback) => { |
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 Optional where Wrapped == Bool { | |
var bool: Bool { | |
switch self { | |
case .some(let value): return value == true | |
case .none: return false | |
} | |
} | |
} | |
var foo: Bool? = true |
NewerOlder