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 TouchGoThroughView: UIView { | |
| override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { | |
| super.point(inside: point, with: event) && pointInsideVisibleSubviews(point, with: event) | |
| } | |
| } | |
| extension UIView { | |
| func pointInsideVisibleSubviews(_ point: CGPoint, with event: UIEvent?) -> Bool { |
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 | |
| struct SortDescriptor<Value> { | |
| let compare: (Value, Value) -> ComparisonResult | |
| } | |
| extension Collection { | |
| func sorted(by sortDescriptors: [SortDescriptor<Element>]) -> [Element] { | |
| sorted { a, b in |
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 XCTest | |
| class NDJSONParserTests: XCTestCase { | |
| let ndJson = "{ \"key\": \"value\" }\n" | |
| func testSimpleNDJSON() { | |
| let twoLines = ndJson + ndJson | |
| XCTAssert(parseDataFromString(twoLines).count == 2) |
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 KeyedDecodingContainer { | |
| func decode<T: NSCoding>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> T? { | |
| let data = try decode(Data.self, forKey: key) | |
| return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T ?? nil | |
| } | |
| } | |
| extension KeyedEncodingContainer { |
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 String { | |
| func draw(fontSize: CGFloat) -> UIImage? { | |
| draw(font: .systemFont(ofSize: fontSize)) | |
| } | |
| func draw(font: UIFont) -> UIImage? { | |
| draw(attributes: [.font: font], backgroundColor: .clear) | |
| } | |
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
| @objcMembers | |
| private class BlockHandler: NSObject { | |
| var block: (() -> Void)? | |
| @objc func runBlock() { | |
| block?() | |
| } | |
| } |
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 | |
| /** | |
| The only benefit SessionDelegate provides is to accompany URL respones with cache control headers which are not provided by the backend at the time of writing. | |
| (Cache control headers in responses let us use Foundation's NSURLCache abilities.) | |
| Once the backend implementation is changed to provide responses with cache control headers SessionDelegate should no longer be used. | |
| NOT THREAD SAFE - it should be used on the delegation queue of NSURLSession | |
| */ |
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 UIKit | |
| class FullContentIntrinsicSizeTableView: UITableView { | |
| override var contentSize: CGSize { | |
| didSet { | |
| if contentSize != oldValue { | |
| invalidateIntrinsicContentSize() | |
| } | |
| } |
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 UIKit | |
| extension UIAlertController { | |
| func setLeftAlignedMessage(_ message: String) { | |
| let paragraphStyle = NSMutableParagraphStyle() | |
| paragraphStyle.alignment = .left | |
| let messageText = NSMutableAttributedString( | |
| string: message, |
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 UIKit | |
| extension UITableView { | |
| func dequeueReusableCell(withIdentifier identifier: String, registerNibIfNeededWithNibName nibName: String) -> UITableViewCell? { | |
| guard let cell = dequeueReusableCell(withIdentifier: identifier) else { | |
| register(UINib(nibName: nibName, bundle: nil), forCellReuseIdentifier: identifier) | |
| return dequeueReusableCell(withIdentifier: identifier) | |
| } |
NewerOlder