Last active
March 6, 2019 01:59
-
-
Save polac24/85262c8a65dde4e8ab7c1b8c1debcd79 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
func weaklyScoped<T: AnyObject>(_ v: @autoclosure () -> T, action: (T) throws -> ()) rethrows -> T? { | |
weak var weakValue: T? | |
do { // optionally autoreleasepool | |
let value = v() | |
try action(value) | |
weakValue = value | |
} | |
return weakValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment