Created
April 11, 2016 08:01
-
-
Save koke/2189a797e8b18573a772c8a34cb1e423 to your computer and use it in GitHub Desktop.
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
class SwitchToLatest { | |
var latest: Cancelable? | |
func switchTo(next: Cancelable) { | |
if let latest = self.latest { | |
latest.cancel() | |
} | |
latest = next | |
} | |
deinit { | |
latest?.cancel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment