Skip to content

Instantly share code, notes, and snippets.

@bartcone
bartcone / gist:ce9e729d1b89bb928175
Created July 13, 2015 01:42
Swift: Curry && Uncurry
func curry <A, B, C> (f: (A, B) -> C) -> A -> (B -> C) {
return { (a: A) -> (B -> C) in
return { (b: B) -> C in
return f(a,b)
}
}
}
func uncurry <A, B, C> (f: A -> B -> C) -> (A, B) -> C {
return { (a: A, b: B) -> C in
@bartcone
bartcone / metatype.swift
Last active November 2, 2015 18:08
metatypes? bad idea?
struct Section {
let info: String
}
struct Row {
let text: String
}
class BaseClass: NSObject {}
class SubclassUno: BaseClass {}
extension BCTextViewCell {
func configure(row: Row) {
self.textView.text = row.text
}
}
extension BCTextFieldCell {
func configure(row: Row) {
self.textField.placeholder = row.text
}
@bartcone
bartcone / ClosuresClosuresClosures
Created January 29, 2016 03:00
Dangling Pointer Playground (weak, unowned)
//: Playground - noun: a place where people can play
import UIKit
class Test {
let handler: () -> ()
deinit {
print("dealloc'd")
@bartcone
bartcone / pointers.swift
Last active August 28, 2016 22:25
Swift 3 Punning?
var endpoint = sockaddr_in()
let f = UnsafeRawPointer(UnsafeMutableRawPointer(&endpoint)).bindMemory(to: sockaddr.self, capacity: 1)