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
// LocationPickerViewController.swift | |
class LocationPickerViewController: UITableViewController { | |
... | |
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
didSelectLocation(locations[indexPath.row]) | |
} | |
} | |
extension UIResponder { |
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
import Foundation | |
public enum Result<Value> { | |
case success(Value) | |
case failure(Error) | |
} | |
public protocol Resource { | |
associatedtype Response | |
func makeRequest() -> URLRequest |
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
// import HMAC in bridging header: | |
// #import <CommonCrypto/CommonHMAC.h> | |
import Foundation | |
enum OTPAlgorithm: String { | |
case sha1, sha256, sha512 | |
var hmacAlgorithm: CCHmacAlgorithm { | |
switch self { |
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
import Foundation | |
public final class Logger { | |
public enum Level: String { | |
case verbose = "◻️" | |
case debug = "◼️" | |
case info = "🔹" | |
case warning = "🔸" | |
case error = "🔴" |
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
/// make { ... } | |
func make<T>(_ setup: (T) -> Void) -> T where T: NSObject { | |
let instance = T() | |
setup(instance) | |
return instance | |
} | |
let label: UILabel = make { | |
$0.text = "Welcome" |
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
import Foundation | |
@_exported import os.log | |
public extension OSLog { | |
convenience init(_ bundle: Bundle = .main, category: String? = nil) { | |
self.init(subsystem: bundle.bundleIdentifier ?? "default", category: category ?? "default") | |
} | |
convenience init(_ aClass: AnyClass, category: String? = nil) { |
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
// https://en.wikipedia.org/wiki/Luhn_algorithm | |
func luhn(_ number: String) -> Bool { | |
return number.reversed().enumerated().map({ | |
let digit = Int(String($0.element))! | |
let even = $0.offset % 2 == 0 | |
return even ? digit : digit == 9 ? 9 : digit * 2 % 9 | |
}).reduce(0, +) % 10 == 0 | |
} |
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 StackViewController: UIViewController { | |
private let scrollView = UIScrollView() | |
private let stackView = UIStackView() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(scrollView) | |
scrollView.addSubview(stackView) | |
setupConstraints() | |
stackView.axis = .vertical |
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
import Dispatch | |
public final class Atomic<A> { | |
private var _value: A | |
private let queue: DispatchQueue | |
public init(_ value: A, targetQueue: DispatchQueue? = nil) { | |
_value = value | |
queue = DispatchQueue(label: "Atomic", attributes: .concurrent, target: targetQueue) |
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
import Foundation | |
open class AsyncOperation: Operation { | |
private enum State: String { | |
case ready = "isReady" | |
case executing = "isExecuting" | |
case finished = "isFinished" | |
} |
OlderNewer