Skip to content

Instantly share code, notes, and snippets.

@Pearapps
Last active January 19, 2016 04:56
Show Gist options
  • Save Pearapps/a367fa51c059019be4b1 to your computer and use it in GitHub Desktop.
Save Pearapps/a367fa51c059019be4b1 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
func makeView<ViewType: UIView>(f: () -> ViewType, translatesAutoresizingMaskIntoConstraints: Bool) -> ViewType {
let view = f()
view.translatesAutoresizingMaskIntoConstraints = translatesAutoresizingMaskIntoConstraints
return view
}
final class MyView: UIView {
init(string: String) {
super.init(frame: CGRectZero)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
func un<A, B>(f : A -> B, a: A) -> () -> B {
return {
f(a)
}
}
let view: MyView = makeView(un(MyView.init, a: "String that goes into initializer"), translatesAutoresizingMaskIntoConstraints: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment