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 Cocoa | |
// Operations | |
protocol Stringable { | |
func stringify() -> String | |
} | |
protocol Evaluatable { |
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
//: [Previous](@previous) | |
import Foundation | |
// One per function | |
final class Stub { | |
let name: String | |
let cmp: (AnyCall, AnyCall) -> Bool | |
init(name: String, cmp: (AnyCall, AnyCall) -> Bool) { | |
self.name = name |
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 Foundation | |
func cast<T>(any: Any) -> T { | |
print(T.self) // Optional<String> | |
print(any) // nil | |
let value = any as! T | |
//Could not cast value of type 'Swift.Optional<Swift.String>' (0x11ad4b028) to 'Swift.String' (0x1118024c8). | |
print(value) |
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 | |
protocol SomeServiceProtocol { | |
func doSomeStuff(); | |
} | |
class SomeService : SomeServiceProtocol { | |
func doSomeStuff() { |
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 UIKit | |
import ReactiveCocoa | |
// Bind property to any setter | |
func <~ <T> (left: T->Void , right: AnyProperty<T>) -> Disposable { | |
return left <~ right.producer | |
} | |
// Bind signal producer to any setter | |
func <~ <T> (left: T->Void , right: SignalProducer<T, NoError>) -> Disposable { |
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 | |
// Simple struct to be fullfilled from JSON | |
struct User { | |
let name: String | |
let age: Int | |
} |
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 | |
protocol Cat { | |
func meow() -> String | |
} | |
protocol Dog { | |
func bark() -> 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
class Murzik : Cat { | |
func meow() -> String { | |
return "Meeooow" | |
} | |
} | |
class Muhtar : Dog { | |
func bark() -> String { | |
return "Woof" | |
} |
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" | |
class ServiceLocator { | |
private var registry : [String: Any] = [:] | |
func registerService<T>(service: T) { |
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 | |
class TableView { | |
init() {} | |
struct DataSource { | |
let numberOfRows : () -> Int | |
} | |
var delegate : DataSource? |