Last active
December 24, 2015 22:53
-
-
Save JoshuaSullivan/34cdb4315d79b0a1d85d to your computer and use it in GitHub Desktop.
An Exploration of Capture Semantics. Read the blog post: http://www.chibicode.org/?p=28
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 attemptLogin(user: String, password: String) { | |
self.loginRequest = APIClient.sharedClient().createLoginRequest(user:user, password:password) { | |
result in | |
switch result { | |
case .Success(let data): | |
parseLoginData(data) // Compiler error: implicit reference to self | |
case .Failure(let error): | |
errorHandlingMethod(error) // Compiler error: implicit reference to self | |
} | |
} | |
} |
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 attemptLogin(user: String, password: String) { | |
self.loginRequest = APIClient.sharedClient().createLoginRequest(user:user, password:password) { | |
result in | |
switch result { | |
case .Success(let data): | |
self.parseLoginData(data) | |
case .Failure(let error): | |
self.errorHandlingMethod(error) | |
} | |
} | |
} |
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 attemptLogin(user: String, password: String) { | |
self.loginRequest = APIClient.sharedClient().createLoginRequest(user:user, password:password) { | |
[unowned self] result in | |
switch result { | |
case .Success(let data): | |
self.parseLoginData(data) | |
case .Failure(let error): | |
self.errorHandlingMethod(error) | |
} | |
} | |
} |
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 attemptLogin(user: String, password: String) { | |
self.loginRequest = APIClient.sharedClient().createLoginRequest(user:user, password:password) { | |
[weak self] result in | |
guard let strongSelf = self else { return } | |
switch result { | |
case .Success(let data): | |
strongSelf.parseLoginData(data) | |
case .Failure(let error): | |
strongSelf.errorHandlingMethod(error) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment