/combine-extensions

Extensions for Apple Combine framework

Primary LanguageSwiftMIT LicenseMIT

combine-extensions

CI SwiftPM 5.9 Platforms @maximkrouk

Extensions for Apple Combine framework.

NOTE: The package is in beta

TODO

  • Proxies

    • DelegateProxy
    • PublishersProxy
    extension PublishersProxy where Base: UISearchBar {
      /// Combine wrapper for `UISearchBarDelegate.searchBarCancelButtonClicked(_:)`
    	public var cancelButtonClicked: some Publisher<Void, Never> {
    		let selector = _makeMethodSelector(
    			selector: #selector(UISearchBarDelegate.searchBarCancelButtonClicked(_:)),
    			signature: base.delegate?.searchBarCancelButtonClicked(_:)
    		)
    		return delegateProxy.proxy_intercept(selector).replaceOutput(with: ())
    	}
    
    	private var delegateProxy: UISearchBarDelegateProxy {
    		.proxy(for: base, \.delegate)
    	}
    }
    
    private class UISearchBarDelegateProxy: 
      DelegateProxy<UISearchBarDelegate>, 
      UISearchBarDelegate 
    {}
  • TypeErasure

    • NoOptionsScheduler
    • AnySubject
    • AnySubscriber
  • Selectors interception

    See combine-interception

  • Cancellables

    • NonScopedCancellable
  • Operators (todo: implement using separate Publisher types instead of erasing to AnyPublisher)

    • SinkOnce
    • SinkEvents
    • SinkValues
  • Subjects:

    • PublishSubject
  • Subscribers

    • CancelTrackingSubscriber
  • Subscriptions

    • CancelTrackingSubscription
  • DemandBuffer

  • Materialize/Dematerialize

  • Relays

  • Look at CombineExt for more ideas

Exports

Installation

Basic

You can add CombineExtensions to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter "https://github.com/capturecontext/combine-extensions.git" into the package repository URL text field
  3. Choose products you need to link them to your project.

Recommended

If you use SwiftPM for your project, you can add CombineExtensions to your package file.

.package(
  url: "https://github.com/capturecontext/combine-extensions.git", 
  .upToNextMinor(from: "0.2.0")
)

Do not forget about target dependencies:

.product(
  name: "CombineExtensions", 
  package: "combine-extensions"
)
.product(
  name: "CombineExtensionsMacros", 
  package: "combine-extensions"
)

License

This library is released under the MIT license. See LICENCE for details.

See [ACKNOWLEDGMENTS][ACKNOWLEDGMENTS] for inspiration references and their licences.