Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block danielgarbien

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Timer_iOS9
private class BlockHandler: NSObject {
var block: (() -> Void)?
@objc func runBlock() {
View FullContentIntrinsicSizeTableView.swift
import UIKit
class FullContentIntrinsicSizeTableView: UITableView {
override var contentSize: CGSize {
didSet {
if contentSize != oldValue {
View UIAlertController+LeftAlignedMessage.swift
import UIKit
extension UIAlertController {
func setLeftAlignedMessage(_ message: String) {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .left
let messageText = NSMutableAttributedString(
string: message,
View UITableView+Registration
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)
View Delay.swift
func delay(_ delay: Double, closure: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: closure)
View SimpleCollectionViewDataSource.swift
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]
danielgarbien / SessionDelegate.swift
Last active Mar 14, 2018
Simple network synchronizer with caching
View SessionDelegate.swift
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
View NDJSONParserTests.swift
import Foundation
import XCTest
class NDJSONParserTests: XCTestCase {
let ndJson = "{ \"key\": \"value\" }\n"
func testSimpleNDJSON() {
let twoLines = ndJson + ndJson
XCTAssert(parseDataFromString(twoLines).count == 2)
View SafeFetchedResultsController.swift
import Foundation
import CoreData
class SafeFetchedResultsController: NSFetchedResultsController {
private weak var safeDelegate: NSFetchedResultsControllerDelegate?
override var delegate: NSFetchedResultsControllerDelegate? {
get {
return safeDelegate
View ContainmentWithAutoLayout.swift
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) {
You can’t perform that action at this time.