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
extension Equatable { | |
func isAny(of candidates: Self...) -> Bool { | |
return candidates.contains(self) | |
} | |
} | |
// Usage: | |
[1, 2, 3].isAny(of: 4, 1) // => true |
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
extension UIEdgeInsets: ExpressibleByDictionaryLiteral { | |
public typealias Key = EdgeKey | |
public typealias Value = CGFloat | |
public enum EdgeKey { | |
case top | |
case left | |
case bottom | |
case right | |
} |
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
protocol Screenshottable { | |
func screenshot() -> UIImage? | |
} | |
extension UIView: Screenshottable { | |
func screenshot() -> UIImage? { | |
let renderer = UIGraphicsImageRenderer(bounds: bounds) | |
return renderer.image { _ in | |
drawHierarchy(in: self.bounds, afterScreenUpdates: false) |
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 UIImage { | |
public var original: UIImage { return withRenderingMode(.alwaysOriginal) } | |
public var template: UIImage { return withRenderingMode(.alwaysTemplate) } | |
} |
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
extension Optional { | |
public func map<T>(_ keyPath: KeyPath<Wrapped, T>) -> T? { | |
return map({ $0[keyPath: keyPath] }) | |
} | |
} |
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
# Display shared libraries that your binary attempts to load | |
otool -L <binary> | |
# Display DYLD symbols for exports and imports | |
nm <binary> |
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 XCTest | |
class MyTestCase: XCTestCase { | |
func testExample() { | |
XCTAssertTrue(true) | |
} | |
} | |
MyTestCase.defaultTestSuite.run() |
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
/// 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 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 { |