Skip to content

Instantly share code, notes, and snippets.

View JARinteractive's full-sized avatar

James Rantanen JARinteractive

View GitHub Profile
@JARinteractive
JARinteractive / Image.swift
Last active October 30, 2019 21:29
Image Enum
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 {
@JARinteractive
JARinteractive / CGHelpers.swift
Last active December 8, 2017 16:37
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)
@JARinteractive
JARinteractive / SimpleTable.swift
Created February 18, 2016 22:02
RxSugar TableDelegate for single section table
import UIKit
import RxSwift
import RxSugar
protocol GenericTableCell: NSObjectProtocol {
typealias Class = Self
typealias ValueType
func populate(value: ValueType)
}
@JARinteractive
JARinteractive / WaitUntil.swift
Last active September 4, 2022 14:40
wait for condition to be true
// https://gist.github.com/JARinteractive/7fb33b6b0043f365ddfd
import Foundation
import XCTest
@discardableResult
public func AssertEventuallyTrue(file: StaticString = #file, line: UInt = #line, _ checkSuccess: @autoclosure () -> Bool) -> Bool {
    return AssertEventuallyTrue(10.0, file: file, line: line, checkSuccess)
}
@discardableResult
@JARinteractive
JARinteractive / main.swift
Last active July 31, 2017 22:31
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())