Skip to content

Instantly share code, notes, and snippets.

@akisute
Last active August 29, 2015 14:12
Show Gist options
  • Save akisute/73861de3e6bc15bbf4de to your computer and use it in GitHub Desktop.
Save akisute/73861de3e6bc15bbf4de to your computer and use it in GitHub Desktop.
Basic example of how to handle delegate patterns in ReactiveCocoa, Swift
self.myDisposable = provider.mySignal.subscribeNext({(someObject) -> RACSignal! in
// do anything you want
return nil
})
// if you want to unsubscribe, then
self.myDisposable.dispose()
// this is like we usually nilify delegate, but such explicit memory management is always a bad thing
// there should be some better practice I believe
private let __mySignal: RACSubject = RACSubject()
var mySignal: RACSignal {
get {
return self.__mySignal
}
}
override func someDelegate(sender: SomeSenderClass) {
self.__mySignal.sendNext(someObject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment