中文)
CombineX.Foundation(这个库提供了对 Combine + Foundation
的另一种实现,基于 CombineX 构建。
DispatchQueue
JSONDecoder
JSONEncoder
NotificationCenter
OperationQueue
PropertyListDecoder
PropertylistEncoder
RunLoop
Timer
URLSession
状态
与 Combine beta 5 兼容。
注意
此库仍在测试阶段,请不要在生产环境中使用!
示例
定时器
let schedule = Timer.cx.publish(every: 1, on: RunLoop.main, in: .default)
URL会话
let ping = URLSession.shared.cx.dataTaskPublisher(for: host)
通知中心
let event = NotificationCenter.default.cx.publisher(for: name)
调度器
let cancel = upstream
.subscribe(on: workQueue.rx.scheduler)
.receive(on: RunLoop.main.rx.scheduler)
.sink { v in
}
尝试一下
Swift包管理器
在你的 Package.swift
pkg.dependencies.append(
.package(url: "https://github.com/CombineXCommunity/CombineX.Foundation", ._branchItem("master"))
)
相关
更多
为什么不用Combine直接?
请参见这里。
为什么接口与Combine不一致?
Combine
直接扩展系统类型。如果在同一次地位置再次定义相同的语句,Swift将无法编译。例如
extension URLSession {
struct DataTaskPublisher: Publisher {
// ...
}
}
如果接口不一致,迁移会非常困难吗?
CombineX.Compatible提供了所有cx
接口的实现,但是基于Combine
,无CombineX
依赖。它可以帮助您轻松迁移。