Skip to content

Instantly share code, notes, and snippets.

@andersio
Last active July 5, 2016 16:30
Show Gist options
  • Select an option

  • Save andersio/af06266dc561002122133058096342d7 to your computer and use it in GitHub Desktop.

Select an option

Save andersio/af06266dc561002122133058096342d7 to your computer and use it in GitHub Desktop.
import Result
import ReactiveCocoa
import Foundation
/*:
## Sandbox
A place where you can build your sand castles 🏖.
*/
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
class Token: NSObject {
func receive() {
print("cleanup")
}
}
var token: Token? = Token()
token?.rac_willDeallocSignal()
.subscribeCompleted { [weak token = token!] in
print("\(token == nil)")
NSNotificationCenter
.defaultCenter()
.removeObserver(token!,
name: "RACReceive",
object: nil)
}
NSNotificationCenter
.defaultCenter()
.addObserver(token!,
selector: #selector(Token.receive),
name: "RACReceive",
object: nil)
NSNotificationCenter
.defaultCenter()
.postNotificationName("RACReceive",
object: nil,
userInfo: nil)
token = nil
NSNotificationCenter
.defaultCenter()
.postNotificationName("RACReceive",
object: nil,
userInfo: nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment