Skip to content

Instantly share code, notes, and snippets.

@LutherBaker
LutherBaker / CGHelpers.swift
Created July 31, 2017 22:26 — forked from JARinteractive/CGHelpers.swift
Simplify frame-based layout
// https://gist.github.com/JARinteractive/96cbba8f35dcd10bbb77
import UIKit
extension CGSize {
public func centered(in rect: CGRect) -> CGRect {
let centeredPoint = CGPoint(x: rect.minX + abs(rect.width - width) / 2, y: rect.minY + abs(rect.height - height) / 2)
let size = CGSize(width: min(self.width, rect.width), height: min(self.height, rect.height))
let point = CGPoint(x: max(centeredPoint.x, rect.minX), y: max(centeredPoint.y, rect.minY))
return CGRect(origin: point, size: size)
@LutherBaker
LutherBaker / SimpleTable.swift
Created July 31, 2017 22:28 — forked from JARinteractive/SimpleTable.swift
RxSugar TableDelegate for single section table
import UIKit
import RxSwift
import RxSugar
protocol GenericTableCell: NSObjectProtocol {
typealias Class = Self
typealias ValueType
func populate(value: ValueType)
}
@LutherBaker
LutherBaker / WaitUntil.swift
Created July 31, 2017 22:29 — forked from JARinteractive/WaitUntil.swift
wait for condition to be true
import Foundation
func waitUntil(_ checkSuccess: @autoclosure ()->Bool) {
return waitUntil(1.0, checkSuccess)
}
func waitUntil(_ timeout: Double, _ checkSuccess: @autoclosure ()->Bool) {
let startDate = NSDate()
var success = false
while !success && abs(startDate.timeIntervalSinceNow) < timeout {
@LutherBaker
LutherBaker / main.swift
Created July 31, 2017 22:31 — forked from JARinteractive/main.swift
simple main.swift to prevent running apps during unit testing
import UIKit
private func delegateClassName() -> String? {
guard NSClassFromString("XCTestCase") == nil else { return nil }
return NSStringFromClass(AppDelegate)
}
UIApplicationMain(Process.argc, Process.unsafeArgv, nil, delegateClassName())
@LutherBaker
LutherBaker / struct_vs_inheritance.swift
Created March 13, 2018 04:05 — forked from AliSoftware/struct_vs_inheritance.swift
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
@LutherBaker
LutherBaker / CustomTextField.swift
Created April 29, 2018 00:50 — forked from soggybag/CustomTextField.swift
Adds border, corner radius, and padding to the UITextField. These properties can be set via the attribute inspector in storyboard.
import UIKit
@IBDesignable
class CustomTextField: UITextField {
var padding: UIEdgeInsets {
get {
return UIEdgeInsets(top: 0, left: paddingValue, bottom: 0, right: paddingValue)
}
}