项目介绍:
项目简介
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