View C-Localized.swift
class NatureViewController: UIViewController { | |
@Localized(.natureTitle) | |
@IBOutlet private var label: UILabel! | |
@Localized(.saveNatureButton) | |
@IBOutlet private var button: UIButton! | |
} |
View LocalizationKey.swift
enum LocalizationKey: String { | |
case | |
natureTitle, | |
saveNatureButton | |
} | |
extension LocalizationKey { | |
var string: String { | |
NSLocalizedString(rawValue, comment: rawValue) | |
} |
View Localizable.swift
protocol Localizable { | |
func set(localization: LocalizationKey) | |
} | |
extension UIButton: Localizable { | |
func set(localization key: LocalizationKey) { | |
setTitle(key.string, for: .normal) | |
} | |
} |
View Localized.swift
@propertyWrapper | |
struct Localized<T: Localizable> { | |
private let key: LocalizationKey | |
var wrappedValue: T? = nil { | |
didSet { | |
wrappedValue?.set(localization: key) | |
} | |
} | |
View A-Localized.swift
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) |
View B-Localized.swift
class NatureViewController: UIViewController { | |
@Localized("natureTitle") | |
@IBOutlet private var label: UILabel! | |
@Localized("saveNatureButton") | |
@IBOutlet private var button: UIButton! | |
} |
View UIFont+.swift
// | |
// UIFont+.swift | |
// Autofriend | |
// | |
// Created by Pilipenko Dima on 10/9/17. | |
// Copyright © 2017 dimpiax. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
View iso8601.swift
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 |
View promiseUtils.js
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) => { |
View Optional+.swift
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