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 extension Optional { | |
func expectedToBe(_ logMessage: String? = nil, line: Int = #line, file: StaticString = #file) -> Wrapped? { | |
switch self { | |
case let .some(some): return some | |
case .none: | |
print("[OPTIONAL] \(#function) \(file):\(line) message \(String(describing: logMessage))") | |
return .none | |
} | |
} | |
} |
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 UIKit | |
class ViewController: UIViewController { | |
var state: State { | |
didSet { | |
label.text = state.debugDescription | |
// While the code is running on the main thread, the undo manager doesn’t update its state until after `registerUndo` returns. Using the DispatchQueue block allows the UI update to wait until this undo/redo operation completes. | |
DispatchQueue.main.async { |
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 extension UIDevice { | |
public enum `Type` { | |
case iPad | |
case iPhone_unknown | |
case iPhone_5_5S_5C | |
case iPhone_6_6S_7_8 | |
case iPhone_6_6S_7_8_PLUS | |
case iPhone_X_Xs | |
case iPhone_Xs_Max |
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 UIKit | |
/// A validation rule for text input. | |
public enum TextValidationRule { | |
/// Any input is valid, including an empty string. | |
case noRestriction | |
/// The input must not be empty. | |
case nonEmpty | |
/// The enitre input must match a regular expression. A matching substring is not enough. | |
case regularExpression(NSRegularExpression) |
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
### Keybase proof | |
I hereby claim: | |
* I am astrokin on github. | |
* I am manyak (https://keybase.io/manyak) on keybase. | |
* I have a public key ASAlGYdaDIVXcae81zp0WPM4c2bb5Ky18U_7EHu0dVlgowo | |
To claim this, I am signing this object: |
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
// | |
// Activity.swift | |
// | |
// Created by Zachary Waldowski on 8/21/16. | |
// Copyright © 2016 Zachary Waldowski. Licensed under MIT. | |
// | |
import os.activity | |
private final class LegacyActivityContext { |
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 | |
class FontFitUtil { | |
class func bestFontForText(_ text: String, font: UIFont, container: UIView) -> UIFont { | |
return bestFontForText(text, font: font, container: container.bounds.size) | |
} | |
class func bestFontForText(_ text: String, font: UIFont, container: CGSize) -> UIFont { | |
//make rect to calculate text a little bit smaller |
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 UIKit | |
class AZTextFrameAttributes: NSObject { | |
// MARK: - Properties | |
fileprivate(set) var width: CGFloat = 0 | |
fileprivate(set) var string: String? | |
fileprivate(set) var attributedString: NSAttributedString? | |
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
final class ThreadSafe<A> { | |
private var _value: A | |
private let queue = DispatchQueue(label: "ThreadSafe") | |
init(_ value: A) { | |
self._value = value | |
} | |
var value: A { | |
return queue.sync { _value } | |
} | |
func atomically(_ transform: (inout A) -> ()) { |
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
//MARK: - Observers | |
extension UIViewController { | |
func addObserverForNotification(_ notificationName: Notification.Name, actionBlock: @escaping (Notification) -> Void) { | |
NotificationCenter.default.addObserver(forName: notificationName, object: nil, queue: OperationQueue.main, using: actionBlock) | |
} | |
func removeObserver(_ observer: AnyObject, notificationName: Notification.Name) { | |
NotificationCenter.default.removeObserver(observer, name: notificationName, object: nil) | |
} |