Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A virtual Combine interface that allows you to switch between different Combine implementations.

License

NotificationsYou must be signed in to change notification settings

cx-org/CXShim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github CI StatusInstallSupported Platform

CXShim is a virtual Combine interface that allows you to switch berween system Combine and open source Combine.

With CXShim, you shoudn't write different code for different Combine. If you find you are in need of it, please file an issue.

Installation

Add the following line to the dependencies in yourPackage.swift file:

.package(url:"https://github.com/cx-org/CXShim",.upToNextMinor(from:"0.4.0"),

Requirements

  • Swift 5.0+

Q&A

Why do I need it?

Because Combine has system limitation, and open source Combine doesn't compatible with SwiftUI. With CXShim, You can easily write one package that compatible with SwiftUI, support Linux, and can backward deploy to iOS 9.0.

Is there any downside?

No, CXShim introduce no extra dependency, no runtime cost, no binary size incrementation. It's not infectious. Migrating from Combine to CXShim is a non-breaking change.

Looks great! How can I adopt it?

If your package use Combine, just replace everyimport Combine withimport CXShim, everything will still works fine. And witha little adjustment, your package can support Linux and lower system as well.

Why this library requires iOS 13+ / macOS 10.15+?

Because system Combine is used by default on Apple platforms. Don't worry, you can choose open source Combine manually and get rid of system requirement.

How do I choose which Combine to use?

You can choose Combine implementation by setting environment variableCX_COMBINE_IMPLEMENTATION.

LibraryValue ofCX_COMBINE_IMPLEMENTATION
Combine (default on Apple platforms)Combine
CombineX (default on Linux)CombineX
OthersSee below
$export CX_COMBINE_IMPLEMENTATION=CombineX# for CLI tools, execute with env variable$ swift build ...$ xcodebuild ...# for Xcode GUI, reopen Xcode with env variable$ killall Xcode$ open Package.swift

How it actually works?

CXShim conditionally re-export appropriate Combine implementation. It also fill the gap between different Combine. For example, you would have needed to write different code forCombine andCombineX:

#if BACKWARD_DEPLOYMENT // we are target on lower system and use CombineX// This method is under cx namespace because `URLSession.dataTaskPublisher` // can't be overloaded and always use system Combine.letpub=URLSession.shared.cx.dataTaskPublisher(for: url)#else // use system Combineletpub=URLSession.shared.dataTaskPublisher(for: url)#endif

WithCXShim, you don't need compilation flags anymore:

import CXShim// `cx` namespace is available even if you're using system Combineletpub=URLSession.shared.cx.dataTaskPublisher(for: url)

Can I use other open source Combine?

Yes you can!CXShim support every known Combine implementations and will support any future one. Just set environment variableCX_COMBINE_IMPLEMENTATION to their respective value. If your library is not listed below, feel free to open an issue.

LibraryValue ofCX_COMBINE_IMPLEMENTATION
OpenCombineOpenCombine

Disclaimer: These project are not part of CombineX. They may have different consistent level with Apple's Combine thanwe promised, and not necessarily pass our test suit. We do not make any warranty of any kind for them.

About

A virtual Combine interface that allows you to switch between different Combine implementations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp