This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct Person { | |
var firstName: String | |
var lastName: String | |
var age: Int | |
} | |
extension Person { | |
enum Query { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tableView.register(forReuse: StoryCell.self) | |
let cell = tableView.dequeueReusable(StoryCell.self, for: indexPath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tableView.register(StoryCell.self, forCellReuseIdentifier: "StoryCell") | |
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryCell", for: indexPath) as? StoryCell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder