Observable

可以理解为时间序列。

var ob = Observable.of("1","2","3","4","5","6")
    .map{ Int($0) }
    .filter{        
        if let item = $0, item % 2 == 0 {
             print(item)
            return true
        }
        return false
}

//上面的不会执行,只有订阅时才会执行
ob.subscribe { event in
    print(event)
}

//next(Optional(2))
//next(Optional(4))
//next(Optional(6))
//completed
print("---------")

ob.skip(2).subscribe { (e) in
    print(e)
}
//会跳过前两个
//next(Optional(6))
//completed

ob.subscribe(
    onNext: { e in
        print(e ?? "")
    },
    onError: { print($0)},
    onCompleted: { print("is Completed") } ,
    onDisposed: { }
)

Operators