This file contains hidden or 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 let null = NSNull() as AnyHashable | |
public enum JSONObject { | |
case array([Any]) | |
case dictionary([String: Any]) | |
case fragment(Any) | |
} | |
extension JSONObject { | |
@inlinable public static func with(_ data: Data, options: JSONSerialization.ReadingOptions = []) throws -> JSONObject { |
This file contains hidden or 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 AVFoundation | |
import RxSwift | |
import RxCocoa | |
extension Reactive where Base: AVCaptureMetadataOutput { | |
/// Reactive wrapper for `delegate`. | |
/// | |
/// For more information take a look at `DelegateProxyType` protocol documentation. | |
public var delegate: DelegateProxy<AVCaptureMetadataOutput, AVCaptureMetadataOutputObjectsDelegate> { |
This file contains hidden or 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
// | |
// TooltipView.swift | |
// Customizable Tooltips | |
// | |
// Copyright © 2017 Simon Wuyts | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This file contains hidden or 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 AnyEquatableBase { | |
func isEqual(to other: AnyEquatableBase) -> Bool { | |
fatalError("overrideMe") | |
} | |
} | |
class AnyEquatableBox<T: Equatable> : AnyEquatableBase { | |
let value: T | |
init(_ value: T) { self.value = value } |
This file contains hidden or 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 | |
extension String { | |
public var JSONminify: String { | |
// http://stackoverflow.com/questions/8913138/ | |
// https://developer.apple.com/reference/foundation/nsregularexpression#//apple_ref/doc/uid/TP40009708-CH1-SW46 | |
let minifyRegex = "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+" | |
if let regexMinify = try? NSRegularExpression(pattern: minifyRegex, options: .caseInsensitive) { |
This file contains hidden or 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
/* | |
Instead of, say: | |
if let definitelyAString = perhapsAString as? String { // yadda... } | |
We now have: | |
String(perhapsAString) // returns a String? (an optional) | |
*/ | |
protocol OptionalLiteralType { |
This file contains hidden or 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 isModal() -> Bool { | |
return self.presentingViewController?.presentedViewController == self | |
|| (self.navigationController != nil && self.navigationController?.presentingViewController?.presentedViewController == self.navigationController) | |
|| self.tabBarController?.presentingViewController is UITabBarController | |
} |
This file contains hidden or 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 OverlayView: UIView { | |
weak var targetView: UIView? | |
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
super.touchesBegan(touches, withEvent: event) | |
targetView?.touchesBegan(touches, withEvent: event) | |
} | |
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { | |
super.touchesMoved(touches, withEvent: event) |
This file contains hidden or 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
//`UITableViewCell` and `UICollectionViewCell` are `Reusable` by defaut | |
//Use the extension method to dequeue an instance of the appropriate `Reusable` | |
class MyVC: UITableViewDataSource { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
tableView | |
.registerReusable(FooCell.self) | |
.registerReusable(BarCell.self) | |
} |
NewerOlder