RxSwift 操作符 (create)

create

ReactiveX:
You can create an Observable from scratch by using the Create operator. You pass this operator a function that accepts the observer as its parameter. Write this function so that it behaves as an Observable — by calling the observer’s onNext, onError, and onCompleted methods appropriately.

create通过该操作符,你可以自己创造一个可观察者。

let ob = Observable<Int>.create { ov in
    ov.onNext(1)
    ov.onNext(2)
    ov.onNext(3)
    ov.onNext(4)
    ov.onCompleted()
    return Disposables.create()
}
ob.subscribe(onNext: { element in
        print(element)
}).disposed(by: bag)

输出:
1
2
3
4

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值