Last active
August 29, 2015 14:12
-
-
Save akisute/73861de3e6bc15bbf4de to your computer and use it in GitHub Desktop.
Basic example of how to handle delegate patterns in ReactiveCocoa, Swift
This file contains 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
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 |
This file contains 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
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