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
//: Playground - noun: a place where people can play | |
import UIKit | |
class VC { | |
var dataSource: DataSource? | |
func viewDidLoad() { | |
let items = dataSource?.numberOfItemsIn(section: 9) ?? -1 | |
print("There are \(items) items") |
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
// | |
// NetworkIndicatorManager.swift | |
// Indicator | |
// | |
// Created by Curt Clifton on 5/17/16. | |
// Copyright © 2016 curtclifton.net. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
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
//: Mutually recursive protocols? | |
protocol State { | |
typealias EventType: Event // error: type may not reference itself as a requirement | |
mutating func transitionWithEvent(event: EventType) | |
} | |
protocol Event { | |
typealias StateType: State // error: type may not reference itself as a requirement | |
var action: (StateMachine<StateType, Self>) -> () { get } |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
struct Foo { | |
private(set) var bar: String | |
let baz: String | |
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
//: Zippers, based on http://learnyouahaskell.com/zippers | |
import UIKit | |
enum FileSystemItem { | |
case File(name: String, data: String) | |
case Folder(name: String, contents: [FileSystemItem]) | |
var name: String { | |
switch self { |
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 | |
// Add a typealias for the child type so different implementors can be specific about the types of their children. | |
protocol NodeRepresentedObject { | |
typealias Child | |
var children: [Child]? {get} | |
} | |
protocol EmailMessage: NodeRepresentedObject { | |
} |
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
// | |
// JSONShape.swift | |
// TypedJSON | |
// | |
// Created by Curt Clifton on 2/7/15. | |
// Copyright (c) 2015 curtclifton.net. All rights reserved. | |
// | |
import Foundation |
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 Counter { | |
var value: Int { get } | |
func moveTowardZero() | |
} | |
func makeCounterStartingAt(value: Int) -> Counter { | |
// Since this class declaration is nested in the generator function, the returned value is only accessible via the Counter protocol | |
class CountImplementation: Counter { | |
var value: Int | |