Swiftpack.co - RxSwiftCommunity/NSObject-Rx as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by RxSwiftCommunity.
RxSwiftCommunity/NSObject-Rx 5.2.2
Handy RxSwift extensions on NSObject, including rx.disposeBag.
⭐️ 603
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/RxSwiftCommunity/NSObject-Rx.git", from: "5.2.2")



If you're using RxSwift, you've probably encountered the following code more than a few times.

class MyObject: Whatever {
	let disposeBag = DisposeBag()


You're actually not the only one; it has been typed many, many times.

Search screenshot showing many, many results.

Instead of adding a new property to every object, use this library to add it for you, to any subclass of NSObject.

  .bind(to: otherThing)
  .disposed(by: rx.disposeBag)


It'll work just like a property: when the instance is deinit'd, the DisposeBag gets disposed. It's also a read/write property, so you can use your own, too.

If you want to add a DisposeBag to an Object that does not inherit from NSObject, you can also implement the protocol HasDisposeBag, and you're good to go. This protocol provides a default DisposeBag called disposeBag.



Add to your Podfile:

pod 'NSObject+Rx'

And that'll be 👌


Add to Cartfile:

github "RxSwiftCommunity/NSObject-Rx"

Add frameworks to your project (no need to "copy items if needed")

Run carthage update or carthage update --platform ios if you target iOS only

Add run script build phase /usr/local/bin/carthage copy-frameworks with input files being:


And rule ✌️


Source files are in the root directory. We use CocoaPods to develop, check out the unit tests in the Demo project.


MIT obvs.

Tim Cook dancing to the sound of a permissive license.


Stars: 603
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

SPM-only release to expose HasDisposeBag
2 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics