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 | |
import UIKit | |
/** | |
* Coordinates contentInset on scroll view to always show full content on keyboard appearing. | |
*/ | |
class KeyboardAwareScrollViewCoordinator: NSObject { | |
let scrollView: UIScrollView | |
private let originalContentInset: UIEdgeInsets |
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 | |
import UIKit | |
import CoreData | |
class FetchedResultsControllerTableDelegate: NSObject { | |
let tableView: UITableView | |
var preserveSelection: Bool = true | |
var didEndUpdates: (() -> Void)? | |
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 | |
import CoreData | |
class CoreDataStack { | |
let mainContext: NSManagedObjectContext | |
private let persistentStoreCoordinator: NSPersistentStoreCoordinator | |
private let managedObjectModel: NSManagedObjectModel | |
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 | |
import UIKit | |
import CoreData | |
class FetchedResultsTableDataSource: NSObject { | |
typealias CellForRowAtIndexPath = (tableView: UITableView, indexPath: NSIndexPath, object: AnyObject) -> UITableViewCell | |
let fetchedResultController: NSFetchedResultsController | |
private let cellForRowAtIndexPath: CellForRowAtIndexPath |
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 | |
extension UIViewController { | |
/** | |
Add childController with no transition. | |
Embeds its view in container. | |
Calls didMove(toParentViewController:) on childController at a last step. | |
*/ | |
func addImmediately(childController: UIViewController, embeddedIn container: UIView) { |
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 | |
import CoreData | |
class SafeFetchedResultsController: NSFetchedResultsController { | |
private weak var safeDelegate: NSFetchedResultsControllerDelegate? | |
override var delegate: NSFetchedResultsControllerDelegate? { | |
get { | |
return safeDelegate |
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 | |
import XCTest | |
class NDJSONParserTests: XCTestCase { | |
let ndJson = "{ \"key\": \"value\" }\n" | |
func testSimpleNDJSON() { | |
let twoLines = ndJson + ndJson | |
XCTAssert(parseDataFromString(twoLines).count == 2) |
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 | |
/** | |
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 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 UIKit | |
class SimpleCollectionViewDataSource<Cell: AnyObject, Object>: NSObject, UICollectionViewDataSource { | |
var objects: [[Object]] | |
func objectAtIndexPath(indexPath: NSIndexPath) -> Object { | |
return objects[indexPath.section][indexPath.row] | |
} |
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
func delay(_ delay: Double, closure: @escaping () -> Void) { | |
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: closure) | |
} |
OlderNewer