Skip to content

Instantly share code, notes, and snippets.

@sgr-ksmt
Last active August 22, 2017 21:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgr-ksmt/d8d7dba92588c8e5b843 to your computer and use it in GitHub Desktop.
Save sgr-ksmt/d8d7dba92588c8e5b843 to your computer and use it in GitHub Desktop.
Swift : autoreleasepool + try
public func autoreleasepool(@noescape code: () throws -> ()) rethrows {
try {
var error: ErrorType?
autoreleasepool {
do {
try code()
} catch (let e) {
error = e
}
}
if let error = error {
throw error
}
}()
}
func doSomething {
do {
try autoreleasepool {
try ~~~~~ // ★
}
} catch (let e) {
print(e) // ★'s error is caught here!
}
}
@yanli0303
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment