Skip to content

Instantly share code, notes, and snippets.

@bgerstle
Last active September 15, 2015 14:11
Show Gist options
  • Select an option

  • Save bgerstle/cba56a17845e8bc227cb to your computer and use it in GitHub Desktop.

Select an option

Save bgerstle/cba56a17845e8bc227cb to your computer and use it in GitHub Desktop.
Trying to "strongify" self in a closure in Xcode 7 GM Swift 2.0
Welcome to Apple Swift version 2.0 (700.0.59 700.0.72). Type :help for assistance.
2> import Foundation
3> class Foo {
4. func guardOptSelf() -> () throws -> Void {
5. return { [weak self] in
6. guard let self = self else { throw NSError(domain: "I was destroyed!", code: 1, userInfo: nil) }
7. }
8. }
9. }
repl.swift:6:19: error: pattern matching in a condition requires the 'case' keyword
guard let self = self else { throw NSError(domain: "I was destroyed!", code: 1, userInfo: nil) }
^
case
repl.swift:6:23: error: binary operator '~=' cannot be applied to two 'Foo?' operands
guard let self = self else { throw NSError(domain: "I was destroyed!", code: 1, userInfo: nil) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment