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 ViewController: UIViewController { | |
private let modelLoader: AnyModelLoader<MyModel> | |
init<T: ModelLoading>(modelLoader: T) where T.Model == MyModel { | |
self.modelLoader = AnyModelLoader(loader: modelLoader) | |
super.init(nibName: nil, bundle: nil) | |
} | |
} |
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 ViewController: UIViewController { | |
private let loadModel: ((Result<MyModel>) -> Void) -> Void | |
init<T: ModelLoading>(modelLoader: T) where T.Model == MyModel { | |
loadModel = modelLoader.load | |
super.init(nibName: nil, bundle: nil) | |
} | |
} |
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 viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
loadModel { result in | |
switch result { | |
case .success(let model): | |
render(model) | |
case .error(let error): | |
render(error) | |
} |
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 ModelLoader { | |
func loadAllModels() -> [Model] { … } | |
} |
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 ModelSequence: Sequence { | |
func makeIterator() -> ModelIterator { | |
return ModelIterator() | |
} | |
} |
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 ModelIterator: IteratorProtocol { | |
private let database: Database | |
private var index = 0 | |
init(database: Database = .shared) { | |
self.database = database | |
} | |
mutating func next() -> Model? { | |
let model = database.model(at: index) |
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 searchForModel(matching query: String) -> Model? { | |
for model in ModelSequence() { | |
if model.title.contains(query) { | |
return model | |
} | |
} | |
return nil | |
} |
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 ModelLoader { | |
func loadAllModels() -> AnySequence<Model> { | |
return AnySequence { () -> AnyIterator<Model> in | |
var index = 0 | |
return AnyIterator { | |
let model = database.model(at: index) | |
index += 1 | |
return model | |
} |
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
echo "$(date +%s)" > "buildtimes.log" |
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
startime=$(<buildtimes.log) | |
endtime=$(date +%s) | |
deltatime=$((endtime-startime)) | |
newline=$'\n' | |
echo "[Start] $startime$newline[End] $endtime$newline[Delta] $deltatime" > "buildtimes.log" |