RxSwift-Observable(一)

Observable 可观察序列
sequence 序列

RxSwift-Observable(一)_第1张图片
observable.png

1、无限序列

        let ob = Observable.interval(1, scheduler: MainScheduler.instance)
        ob.subscribe(onNext: { (num) in
            print(num)
        })

2、有穷序列

        let ob = Observable.just([1,2,3,4])
        ob.subscribe(onNext: { (num) in
            print(num)
        }, onCompleted: {
            print("订阅完成")
        })
        //失败
        URLSession.shared.rx.response(request: URLRequest.init(url: URL.init(string: "https://www.baidu.xx")!))
            .subscribe(onNext: { (response,data) in

            }, onError: { (error) in
                print("错误,\(error)")
            })

你可能感兴趣的:(RxSwift-Observable(一))