SPKit
Simple Promise Kit for swift
Install / Use
/learn @piresbruno/SPKitREADME
SPKit is just another Swift promises framework, it prevents the callback hell and supports sync and async code.
It was made be to simple to use, read and maintain.
It works with Xcode 10.2 and Swift 5
How to install SPKit
You can install SPKit using carthage, or just drag the SPKit.swift file to your project.
How to use SPKit
Start the flow by calling SPKit.first, move to the next block by calling .resolve() and finish the flow by calling .complete() or .failure().
Example happy path
SPKit.first { (instance) in
print("first code block")
instance.resolve()
}.then { (instance, result) in
print("next code block")
instance.complete()
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
Example happy path with sync and async
SPKit.first { (instance) in
print("first code exec")
instance.resolve()
}.then { (instance, result) in
DispatchQueue.global().asyncAfter(deadline: .now() + .seconds(1)){
print("async code")
instance.resolve()
}
}.then { (instance, result) in
print("sync code")
instance.resolve("finished stage 2")
}.then { (instance, result) in
print("using result value: \(result as? String ?? "")")
instance.complete()
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
Example error path
SPKit.first { (instance) in
print("first code exec")
instance.resolve()
}.then { (instance, result) in
print("sync code")
instance.resolve("finished stage 2")
}.then { (instance, result) in
print("using result value: \(result as? String ?? "")")
instance.failure("ooppps")
}.onCompleted {(result) in
print("COMPLETED")
}.onFailure {(error) in
print("FAILURE")
}
Doubts or questions
Please open an issue.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
