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 PlaygroundSupport | |
import ReSwift | |
// API | |
protocol API { | |
func loadUsers(completion: @escaping (([User]) -> Void)) | |
} |
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
// Note you can copy this code andn paste it in a Xcode Playground | |
// Simulates working and introduces some randomness | |
func randomSleep() { | |
sleep(arc4random_uniform(2)) | |
} | |
// Item to be produced/consumed | |
struct Item { | |
let id: 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
func arrayToTuple(array: [Int]) -> (Int, Int, Int) { | |
return array.reduce((0, 0, 0)) { temp, item in | |
switch item { | |
case 0..<10: return (temp.0 + 1, temp.1, temp.2) | |
case 10..<100: return (temp.0, temp.1 + 1, temp.2) | |
default: | |
return item > 100 ? (temp.0, temp.1, temp.2 + 1) : temp | |
} | |
} | |
} |
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
1. Comment out @UIApplicationMain in your AppDelegate. | |
2. Create main.swift file with the following code: | |
import Foundation | |
import UIKit | |
let isRunningTests = NSClassFromString("XCTestCase") != nil | |
if isRunningTests { |