Skip to content

Instantly share code, notes, and snippets.

@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)
}
}
@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 / 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 / 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 / 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 / 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)
import UIKit
public enum Image: String {
private static let bundle = Bundle(for: ClassInImageBundle.self)
// Your images here:
case imageOne = "image-1"
case imageTwo = "image-2"
public var uiImage: UIImage {
//
// CustomDynamicAlertView.h
// Week3_inclass
//
// Created by Victor Baro on 18/02/2015.
// Copyright (c) 2015 Produkt. All rights reserved.
//
#import <UIKit/UIKit.h>
@LutherBaker
LutherBaker / introrx.md
Last active November 15, 2017 21:58 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.