Instantly share code, notes, and snippets.

View Loader.swift
protocol Loadable {
var activityIndicator: UIActivityIndicatorView {get}
func showLoaderView()
func hideLoaderView()
}
extension Loadable where Self: UIViewController {
func showLoaderView() {
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
View sg_flatMap.swift
extension Array {
func sg_flatMap<U>(transform: (Generator.Element) -> [U]) -> [U] {
var result = [U]()
for item in self {
result.appendContentsOf(transform(item))
}
return result
}
View simpleMapArray.swift
extension Array {
func map<U>(transform: (element: Generator.Element) -> U) -> [U]{
var elements = [U]()
for item in self {
elements.append(transform(element: item))
}
return elements
}
}