Skip to content

Instantly share code, notes, and snippets.

View feighter09's full-sized avatar

Austin Feight feighter09

View GitHub Profile
@feighter09
feighter09 / changeKeyboardDoneColor.swift
Last active July 25, 2022 06:10
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 =)
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 June 25, 2021 19:24
Set global font for iOS app in one place
// MARK: - Swizzling
extension UIFont {
class var defaultFontFamily: String { return "Georgia" }
override public class func initialize()
{
if self == UIFont.self {
swizzleSystemFont()
}
}
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 October 1, 2019 14:23
A helper to weakly capture an object in a block
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 April 28, 2016 04:34
IBInspectable UIView Extensions for Fun and Profit
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 }
}
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 08:51
Functional View Controllers from Chris Eidhof's talk @ FunSwiftConf 2015
import UIKit
// MARK: - Building Blocks
struct Screen<A> {
let run: (A -> Void) -> UIViewController
}
extension Screen {
func map<B>(f: A -> B) -> Screen<B>
{
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") {
tableView.register(StoryCell.self, forCellReuseIdentifier: "StoryCell")
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryCell", for: indexPath) as? StoryCell
tableView.register(forReuse: StoryCell.self)
let cell = tableView.dequeueReusable(StoryCell.self, for: indexPath)