View changeKeyboardDoneColor.swift
class Utilities { | |
class func subviewsOfView(view: UIView, withType type: String) -> [UIView] | |
{ | |
let prefix = "<\(type)" | |
var subviewArray = view.subviews.flatMap { subview in subviewsOfView(subview, withType: type) } | |
if view.description.hasPrefix(prefix) { | |
subviewArray.append(view) | |
} | |
View Fonts.swift
// MARK: - Swizzling | |
extension UIFont { | |
class var defaultFontFamily: String { return "Georgia" } | |
override public class func initialize() | |
{ | |
if self == UIFont.self { | |
swizzleSystemFont() | |
} | |
} |
View Regex.swift
struct Regex { | |
let pattern: String | |
let options: NSRegularExpressionOptions | |
private var matcher: NSRegularExpression { | |
return try! NSRegularExpression(pattern: pattern, options: options) | |
} | |
init(pattern: String, options: NSRegularExpressionOptions! = nil) | |
{ |
View Weak.swift
func weak<Object: AnyObject>(_ object: Object, block: @escaping (Object) -> Void) -> () -> Void { | |
return { [weak object] in | |
guard let object = object else { return } | |
block(object) | |
} | |
} | |
func weak<Object: AnyObject, Input>(_ object: Object, block: @escaping (Object, Input) -> Void) -> (Input) -> Void { | |
return { [weak object] in | |
guard let object = object else { return } |
View ViewUtilities.swift
extension UIView { | |
@IBInspectable var borderColor: UIColor? { | |
get { return layer.borderColor.map(UIColor.init) } | |
set { layer.borderColor = newValue?.CGColor } | |
} | |
@IBInspectable var borderWidth: CGFloat { | |
get { return layer.borderWidth } | |
set { layer.borderWidth = newValue } | |
} | |
View Queries.swift
import Foundation | |
struct Person { | |
var firstName: String | |
var lastName: String | |
var age: Int | |
} | |
extension Person { | |
enum Query { |
View FunctionalViewControllers.swift
import UIKit | |
// MARK: - Building Blocks | |
struct Screen<A> { | |
let run: (A -> Void) -> UIViewController | |
} | |
extension Screen { | |
func map<B>(f: A -> B) -> Screen<B> | |
{ |
View spec.swift
override func spec() | |
{ | |
var subject: UIViewController!, viewModel: ViewModel! | |
beforeEach { (subject, viewModel) = self.newSubject } | |
context("once the view has loaded") { | |
beforeEach { subject.loadViewIfNeeded() } | |
describe("events sent to view model") { | |
context("when selection changes") { |
View UglyDequeueCell.swift
tableView.register(StoryCell.self, forCellReuseIdentifier: "StoryCell") | |
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryCell", for: indexPath) as? StoryCell |
View PrettyDequeueCell.swift
tableView.register(forReuse: StoryCell.self) | |
let cell = tableView.dequeueReusable(StoryCell.self, for: indexPath) |
NewerOlder