Skip to content

Instantly share code, notes, and snippets.

View s4cha's full-sized avatar
🎯
Focusing

Sacha DSO s4cha

🎯
Focusing
View GitHub Profile
@s4cha
s4cha / User.swift
Last active October 17, 2016 14:50
struct User {
var 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!
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
api.getUsers().then { users in
for u in users {
print(u.username)
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 ")
}
tableView.register(MyCell.self, forCellReuseIdentifier: “MyCell”)
protocol Reusable: class {
static var reuseIdentifier: String { get }
}
extension MyCell: Reusable {}
extension Reusable {
static var reuseIdentifier: String {
return String(describing: Self.self)
}
}
extension UITableView {
func register<T: UITableViewCell>(_: T.Type) where T: Reusable {
register(T.self, forCellReuseIdentifier: T.reuseIdentifier)
}
}
tableView.register(Mycell.self)