Skip to content

Instantly share code, notes, and snippets.

Avatar

A Wild Austin Feight feighter09

View GitHub Profile
@feighter09
feighter09 / changeKeyboardDoneColor.swift
Last active Jan 22, 2021
Change the keyboard "Done" button color to match the rest of your app! This is a total hack though and is likely to get flagged during app review. If so, try obfuscating =)
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)
}
@feighter09
feighter09 / Fonts.swift
Last active Nov 25, 2020
Set global font for iOS app in one place
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)
{
@feighter09
feighter09 / Weak.swift
Last active Oct 1, 2019
A helper to weakly capture an object in a block
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 }
@feighter09
feighter09 / ViewUtilities.swift
Created Apr 28, 2016
IBInspectable UIView Extensions for Fun and Profit
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 {
@feighter09
feighter09 / FunctionalViewControllers.swift
Last active May 18, 2017
Functional View Controllers from Chris Eidhof's talk @ FunSwiftConf 2015
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)