Swiftpack.co - Package - RxSwiftCommunity/NSObject-Rx
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.



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: 512


SPM-only release to expose HasDisposeBag - 2020-04-23T15:10:35

5.1.0 - 2020-04-11T22:02:44

  • Update RxSwift

5.0.2 - 2019-09-02T10:39:03

  • Add the public modifier access to the disposeBag property

5.0.1 - 2019-08-26T12:51:00

  • Swift 5.0 support
  • using RxSwift 5.0
  • fixing unit tests

5.0.0 - 2019-05-09T18:54:05

4.4.1 - 2018-09-26T20:04:32

Setting Swift 4.2 version in podspec and .swift-version

4.3.0 - 2018-03-22T21:14:18

4.2.0 - 2017-10-27T13:03:13

4.1.1 - 2017-10-27T01:27:47

Same as 4.1.0 except it contains a Carthage fix for Swift 4 / RxSwift 4.0. Thanks @Gurpartap.

3.0.1 - 2017-09-15T16:38:55

Fixes a Carthage installation issue with 3.0.1. See #44.

Add `rx.disposeBag` - 2017-04-30T01:12:33

Make it public!