欢迎光临
我们一直在努力

快速观测框架 – Snail

建站超值云服务器,限时71元/月

快速观测框架 - Snail

项目介绍:

项目简介

snail

安装

Carthage

brew update
brew install carthage
github “UrbanCompass/Snail” “x.x.x”

Swift Package Manager

dependencies: [

.Package(url: "https://github.com/UrbanCompass/Snail.git", majorVersion: 0)

]
Manually

将Snail/Snail添加到项目中t

创建Observables

let observable = Observable<thing>()
订阅Observables

observable.subscribe(

onNext: { thing in ... }, // do something with thing
onError: { error in ... }, // do something with error
onDone: { ... } //do something when it's done

)
Closures are optional too…

observable.subscribe(

onNext: { thing in ... } // do something with thing

)
observable.subscribe(

onError: { error in ... } // do something with error

)

创建Observables变量

let variable = Variable<whatever>(some initial value)
let optionalString = Variable<String?>(nil)
optionalString.asObservable().subscribe(

onNext: { string in ... } // do something with value changes

)

optionalString.value = “something”
let int = Variable<Int>(12)
int.asObservable().subscribe(

onNext: { int in ... } // do something with value changes

)

int.value = 42

其他变量

let just = Just(1) // always returns the initial value (1 in this case)

enum TestError: Error {
case test
}
let failure = Fail(TestError.test) //always fail with error

let n = 5
let replay = Replay(n) // replays the last N events when a new observer subscribes

订阅控制事件

let control = UIControl()
control.controlEvent(.touchUpInside).subscribe(
onNext: { … } // do something with thing
)

let button = UIButton()
button.tap.subscribe(
onNext: { … } // do something with thing
)

github地址:
https://github.com/UrbanCompass/Snail
code4app

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 快速观测框架 – Snail
分享到: 更多 (0)