cx-org/CXFoundation

CombineX + Foundation


Keywords
async, combine, combinex, foundation, publisher, reactive, rx, subscriber
License
MIT

Documentation

CXFoundation(中文)

travis release install platform license dicord

Combine + Foundation, built on top of CombineX.

  • DispatchQueue
  • JSONDecoder
  • JSONEncoder
  • NotificationCenter
  • OperationQueue
  • PropertyListDecoder
  • PropertylistEncoder
  • RunLoop
  • Timer
  • URLSession

Notice

This library is still in beta, so do not use it in production!

🐱

Living examples

Timer

let ping = Timer.cx.publish(every: 1, on: RunLoop.main, in: .default)
    .sink { d in 
        // ping
    }

URLSession

let request = URLSession.shared.cx.dataTaskPublisher(for: host)
    .sink { (data, response) in
        // update ui
    }

NotificationCenter

let observe = NotificationCenter.default.cx.publisher(for: name)
    .sink { notification in
        // 
    }

Scheduler

let cancel = upstream
    .receive(on: RunLoop.main.cx.scheduler)
    .sink { v in
        //
    }

Install

Swift Package Manager

dependencies.append(
    .package(url: "https://github.com/cx-org/CXFoundation", .branch("master"))
)

CocoaPods

pod 'CxFoundation', :git => 'https://github.com/cx-org/CXFoundation.git', :branch => 'master'

Carthage

github "cx-org/CXFoundation" "master"

Related

FAQ

Why not use Combine directly?

See here.

Why are the interfaces not exactly the same as Combine?

Combine directly extends the system type. We can't define the same interface in the same place - it won't compile. Such as:

extension URLSession {
    struct DataTaskPublisher: Publisher {
        // ...
    }
}

If the interfaces are inconsistent, will migration be very troublesome?

CXCompatible provides implementations of all cx interfaces, but based on Combine, no CombineX dependency. It can help you migrate painlessly.