Skip to content

Instantly share code, notes, and snippets.

View fmo91's full-sized avatar

Fernando Martín Ortiz fmo91

View GitHub Profile
//
// FOAttributedStringBuilder.swift
//
// Created by Fernando Ortiz on 18/11/15.
// Copyright © 2015 Fernando Ortiz. All rights reserved.
//
import Foundation
class FOAttributedStringBuilder {
@fmo91
fmo91 / Dequeuable.swift
Last active October 4, 2016 03:49
Dequeuable.swift is a protocol extension that I heavily use in my projects to avoid using string literals while dequeuing cells from table views.
//
// Dequeuable.swift
//
// Created by Fernando Ortiz on 9/30/16.
// Copyright © 2016 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
/**
@fmo91
fmo91 / Registrable.swift
Created October 4, 2016 03:57
Simple protocol extension for easily registering UITableViewCell without hardcoding strings.
//
// Registrable.swift
//
// Created by Fernando Ortiz on 9/30/16.
// Copyright © 2016 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
/**
@fmo91
fmo91 / DogsTableViewDriver.swift
Created January 4, 2017 01:02
A sample UITableView delegate and data source implemented as a separated object
//
// DogsTableViewDriver.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/3/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
@fmo91
fmo91 / DogsViewController.swift
Last active January 4, 2017 01:20
Sample view controller that does not worry about the table view presentation details.
//
// DogsViewController.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/3/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
@fmo91
fmo91 / SampleViewController.swift
Created January 4, 2017 04:29
Sample view controller that is instantiated using xibs.
//
// SampleViewController.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/4/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
@fmo91
fmo91 / AppDelegate.swift
Created January 4, 2017 04:34
Sample AppDelegate that starts the application without using storyboards
//
// AppDelegate.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/3/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
// In the async side...
func someAsyncFunction(completion: @escaping (Error?) -> Void) {
// Something that takes some time to complete.
completion(nil) // Or completion(SomeError.veryBadError)
}
// In the consumer side...
someAsyncFunction { error in
if let error = error {
print("Oops! Something went wrong...")
someAsyncFunction {
anotherAsyncFunction1 {
anotherAsyncFunction2 {
anotherAsyncFunction3 {
anotherAsyncFunction4 {
// Thanks to God this has no error handling 😰
}
}
}
}
func getUser(withID id: Int) -> Future<User> {
return Future { completion in
// Here you call an API
// that returns the user you are looking for.
APIClient.get(getUserURL(id: id)) { user in
completion(.success(user))
}
}
}