Skip to content

Instantly share code, notes, and snippets.

View Pearapps's full-sized avatar

Kenneth Ackerson Pearapps

View GitHub Profile
protocol Kennycol {
func kennyThang() -> String;
}
class KennyClass: Kennycol {
func kennyThang() -> String {
return "example"
}
}
protocol MyDelegate { }
final class MyObject {
let delegate: MyDelegate
init(delegate: MyDelegate) {
self.delegate = delegate
}
}
protocol MyDelegate: class { }
final class MyObject {
weak var delegate: MyDelegate?
}
extension CollectionType where Index: BidirectionalIndexType {
func lastIndexOf(isElement: Generator.Element -> Bool) -> Index? {
return indices.reverse().filter { return isElement(self[$0]) }.first
}
}
@Pearapps
Pearapps / call.swift
Last active January 9, 2016 21:34
Map over an array of instances by currying an class method and then invoking the resulting functions
extension String {
func toUpperCase() -> String {
return uppercaseString
}
}
extension SequenceType {
@warn_unused_result
func mapByCalling<T>(@noescape transformer: (Self.Generator.Element) throws -> (() -> T)) rethrows -> [T] {
return try self.map(transformer).map({ $0() })
//: 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
}
@Pearapps
Pearapps / Double.swift
Created January 30, 2016 23:40
Double Extension
extension Double {
func toFloat() -> CGFloat {
return CGFloat(self)
}
}