QLoop /'kyoo•loop/ - n - Declarative asynchronous operation loops
This guide will help you get started with using QLoop, and assumes you already know your way around Xcode and/or the Swift Package Manager.
Either add it as a submodule or use SwiftPM ...
When importing the library for use in an Xcode project (such as for an iOS or OSX app), then one solid choice is to simply add it as a git submodule:
mkdir -p submodule
git submodule add https://github.com/quickthyme/qloop.git submodule/qloop
Next, link the QLoop.xcodeproj as a dependency of your project by dragging it from the Finder into your open project or workspace.
Once you have the project linked, it's build scheme and products will be
selectable from drop-downs in your Xcode project. Just add QLoop
to your
target's dependencies and libQLoop-<arch>.a
to the linking phase, and you're
all set!
QLoop supports the Swift Package Manager.
It works fine in any Swift project on any Swift platform, including OSX and Linux.
Just add the dependency to your Package.swift
file:
- package:
QLoop
- url:
https://github.com/quickthyme/qloop.git
Then just ...
swift resolve
That's it, nothing else to do except start using it...
import UIKit
import QLoop
class ManaViewController: UIViewController {
@IBAction func magicAction(_ sender: AnyObject?) {
doMagicLoop.perform(true)
}
lazy var doMagicLoop = QLoop<Void, Sparkles>(
onChange: ({ sparkles in
self.manaView.showSparkles()
}),
onError: ({ error in
self.manaView.showError()
}))
}
func MakeSparkles(awesomeSauce: Combustible) -> (((String?), (String?)->()) throws -> ()) {
let powder = grind(awesomeSauce)
return { input, completion in
result = Heat(powder, level: 11)
completion(result)
}
}
func inject() {
manaViewController.doMagicLoop
.bind(path: QLPath<Void, Sparkles>(
QLss(1, MakeSparkles(awesomeSauce: .unicornSriracha)),
QLss(2, SafetyInspectSparkles()))
}
...
func test_when_magicAction_then_it_runs_the_loop() {
subject.magicAction(nil)
XCTAssertEqual(subject.doMagicLoop.input.value, true)
}
...
For more, please check out the demo app , or read the Introduction.