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
extension DispatchQueue { | |
fileprivate static let mainQueueKey = DispatchSpecificKey<()>() | |
static func configureMainQueue() { | |
main.setSpecific(key: mainQueueKey, value: ()) | |
} | |
} | |
public extension DispatchQueue { | |
/// Easy and safe way of checking if the current queue is the main queue |
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
/// Utility Class that can hold on to any number of delegates and invoke arbitrary blocks of code on them | |
public class MulticastDelegate<T: AnyObject> { | |
/// HashTable containing any number of delegates, held weakly | |
private let delegates: NSHashTable<AnyObject> = NSHashTable.weakObjects() | |
/// Adds delegate to list of delegates | |
/// | |
/// - Parameter delegate: Delegate to add to list of known delegates | |
public func add(_ delegate: T) { | |
delegates.add(delegate as AnyObject) |
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 XCTest | |
class MyTestCase: XCTestCase { | |
func testExample() { | |
XCTAssertTrue(true) | |
} | |
} | |
MyTestCase.defaultTestSuite.run() |
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
# Display shared libraries that your binary attempts to load | |
otool -L <binary> | |
# Display DYLD symbols for exports and imports | |
nm <binary> |
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 | |
import RxSwift | |
import RxCocoa | |
extension ObservableType { | |
/// Unwraps an Optional Element if it's present | |
/// | |
/// - Returns: The safely unwrapped item | |
func unwrap<T>() -> Observable<T> where E == Optional<T> { | |
return filter { $0 != nil }.map { $0! } |
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
/// Type erased Optional protocol | |
protocol OptionalType { | |
associatedtype WrapType | |
var isSome: Bool { get } | |
var isNone: Bool { get } | |
var unsafelyUnwrapped: WrapType { get } | |
} |
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 | |
/** | |
A custom namespace _へ__(‾◡◝ )>. | |
General pattern would be: | |
``` | |
extension CustomNamespace where Base: UIView { | |
// This property does not override the existing one | |
var safeAreaInsets: UIEdgeInsets { |
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
/// An UILabel that allows insetting the label | |
class UIInsetLabel: UILabel { | |
/// The insets to inset the main `rect` by | |
var insets: UIEdgeInsets | |
init(insets: UIEdgeInsets) { | |
self.insets = insets | |
super.init(frame: .zero) | |
} | |
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
extension Equatable { | |
func isAny(of candidates: Self...) -> Bool { | |
return candidates.contains(self) | |
} | |
} | |
// Usage: | |
[1, 2, 3].isAny(of: 4, 1) // => true |
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
extension UIEdgeInsets: ExpressibleByDictionaryLiteral { | |
public typealias Key = EdgeKey | |
public typealias Value = CGFloat | |
public enum EdgeKey { | |
case top | |
case left | |
case bottom | |
case right | |
} |