Skip to content

Instantly share code, notes, and snippets.

View fmo91's full-sized avatar

Fernando Martín Ortiz fmo91

View GitHub Profile
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))
}
}
}
@fmo91
fmo91 / overlay.json
Created February 6, 2017 23:49
Sample json created using Google Maps Styling Wizard
[
{
"elementType": "geometry",
"stylers": [
{
"color": "#ebe3cd"
}
]
},
{
private func configureTileOverlay() {
// We first need to have the path of the overlay configuration JSON
guard let overlayFileURLString = Bundle.main.path(forResource: "overlay", ofType: "json") else {
return
}
let overlayFileURL = URL(fileURLWithPath: overlayFileURLString)
// After that, you can create the tile overlay using MapKitGoogleStyler
guard let tileOverlay = try? MapKitGoogleStyler.buildOverlay(with: overlayFileURL) else {
return
@fmo91
fmo91 / renderer-for-overlay.swift
Last active February 7, 2017 13:29
Sample use for rendererForOverlay
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
// This is the final step. This code can be copied and pasted into your project
// without thinking on it so much. It simply instantiates a MKTileOverlayRenderer
// for displaying the tile overlay.
if let tileOverlay = overlay as? MKTileOverlay {
return MKTileOverlayRenderer(tileOverlay: tileOverlay)
} else {
return MKOverlayRenderer(overlay: overlay)
}
}
@fmo91
fmo91 / MapKitGoogleStylerExample.swift
Last active February 7, 2017 13:28
An example on MapKitGoogleStyler library.
//
// ViewController.swift
// MapKitGoogleStylerExample
//
// Created by Fernando Ortiz on 2/6/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
import MapKit
@fmo91
fmo91 / Task.swift
Last active February 8, 2017 03:24
Object oriented swift tasks microframework with composition and concurrency
//
// Task.swift
// TaskFramework
//
// Created by Fernando Ortiz on 2/7/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import Foundation
public enum TaskError: Error {
@fmo91
fmo91 / Request.swift
Last active February 12, 2017 05:30
Sample implementation of a network Request
//
// Request.swift
//
// Created by Fernando Ortiz on 2/12/17.
//
import Foundation
enum HTTPMethod: String {
case get, post, put, patch, delete
@fmo91
fmo91 / NetworkDispatcher.swift
Created February 12, 2017 05:57
Sample NetworkDispatcher
//
// NetworkDispatcher.swift
//
// Created by Fernando Ortiz on 2/11/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import Foundation
import RxSwift
@fmo91
fmo91 / Task.swift
Created February 12, 2017 06:40
Sample Task implementation
//
// Task.swift
//
// Created by Fernando Ortiz on 2/11/17.
//
import Foundation
import RxSwift
class Task<Input, Output> {