Created
April 27, 2015 18:57
-
-
Save drewcrawford/ef7834d3369fa889bcfd to your computer and use it in GitHub Desktop.
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
import Foundation | |
let notification = "MyNotification" | |
struct DontCopy { | |
var value = false | |
mutating func whatever(#callback:() -> ()) { | |
self.value = true | |
NSNotificationCenter.defaultCenter().addObserverForName(notification, object: nil, queue: nil) { (noti) -> Void in | |
self.value = false | |
callback() | |
} | |
} | |
} | |
var dc = DontCopy() | |
assert(dc.value == false) | |
dc.whatever { () -> () in | |
println("Value in callback is \(dc.value)") | |
} | |
assert(dc.value == true) | |
NSNotificationCenter.defaultCenter().postNotificationName(notification, object: nil) | |
println("Value out of callback is \(dc.value)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment