Skip to content

Instantly share code, notes, and snippets.

A Wild Austin Feight feighter09

Block or report user

Report or block feighter09

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 }
View Queries.swift
import Foundation
struct Person {
var firstName: String
var lastName: String
var age: Int
}
extension Person {
enum Query {
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") {
@feighter09
feighter09 / TableViewCellType.swift
Created Mar 28, 2017
Make tableviews a bit safer
View TableViewCellType.swift
protocol CellType {
static var identifier: String { get }
}
extension CellType {
static var identifier: String { return "\(Self.self)" }
}
extension UITableView {
func register<Cell>(forReuse cell: Cell.Type)
View PrettyDequeueCell.swift
tableView.register(forReuse: StoryCell.self)
let cell = tableView.dequeueReusable(StoryCell.self, for: indexPath)
View UglyDequeueCell.swift
tableView.register(StoryCell.self, forCellReuseIdentifier: "StoryCell")
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryCell", for: indexPath) as? StoryCell
View KeylessUserDefaultsIdealUsage2.swift
let defaults = Defaults()
let hasLoggedIn = true
defaults.save(true, forKey: .LoggedIn)
defaults.save(false, forKey: .NotificationsEnabled)
let regularOrder = Order(item: "Cold Brew", size: .Large)
let alternateOrder = Order(item: "Latte", size: .Small)
defaults.save(regularOrder)
defaults.save(alternateOrder, forKey: .Alternate)
View KeylessUserDefaultsUsage.swift
let defaults = Defaults()
let person = Person(firstName: "Austin", lastName: "Feight", age: -3)
defaults.save(person)
let fetched: Person? = defaults.fetch(Person.self)
print("\(fetched!.firstName) \(fetched!.lastName) is \(fetched!.age) years old")
// Output: Austin Feight is -3 years old
View KeylessUserDefaultsPersonExtension.swift
extension Person: DefaultConvertible {
private static let firstNameKey = "first_name"
private static let lastNameKey = "last_name"
private static let ageKey = "age"
var serialized: [String : AnyObject] {
return
[
Person.firstNameKey: firstName as AnyObject,
Person.lastNameKey: lastName as AnyObject,
View IdealKeylessUserDefaults.swift
struct Person {
var firstName: String
var lastName: String
var age: String
}
let person = Person(firstName: "Austin", lastName: "Feight", age: -3)
UserDefaults.standard.set(person)
let fetchedPerson = UserDefaults.standard.fetch(Person.self)
You can’t perform that action at this time.