Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
extension MyCell: Reusable {}
protocol Reusable: class {
static var reuseIdentifier: String { get }
}
tableView.register(MyCell.self, forCellReuseIdentifier: “MyCell”)
api.getUsers().then { users in
// strongly typed [User] !
}.onError { e in
print(e) // Handle any networking error that might happen
}.finally {
print("Whatever happens I'll be executed ")
}
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
api.getUsers().then { users in
for u in users {
print(u.username)
@s4cha
s4cha / Api2.swift
Last active October 17, 2016 16:35
import ws
import then
let api = Api()
struct Api {
private let ws = WS("http://jsonplaceholder.typicode.com")
func getUsers() -> Promise<[User]> { // We want [User] back!
@s4cha
s4cha / User.swift
Last active October 17, 2016 14:50
struct User {
var username = ""
}
import Arrow
extension User: ArrowParsable {
mutating func deserialize(_ json: JSON) {
username <-- json["username"]
}
}
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
api.getUsers().then { json in
print(json)
}
@s4cha
s4cha / Api.swift
Last active October 17, 2016 16:37
import ws
import then // Needed to import Promise Type
import Arrow // Needed to import JSON Type
let api = Api() // Define global api
struct Api {
// Connect to the base URL
private let ws = WS("http://jsonplaceholder.typicode.com")