Created
March 17, 2017 02:20
-
-
Save kateinoigakukun/c83540ae925de633eae7afd667c6ec84 to your computer and use it in GitHub Desktop.
黒魔術 #CodePiece
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSObject { | |
struct AssociatedKeys { | |
static var disposeBagKey = "DisposeBagKey" | |
} | |
var disposeBag: DisposeBag { | |
get { | |
guard let bag = objc_getAssociatedObject(self, &type(of: self).AssociatedKeys.disposeBagKey) as? DisposeBag else { | |
let newDisposeBag = DisposeBag() | |
self.disposeBag = newDisposeBag | |
return newDisposeBag | |
} | |
return bag | |
} | |
set { | |
objc_setAssociatedObject(self, &type(of: self).AssociatedKeys.disposeBagKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment