Created
March 31, 2015 10:28
-
-
Save garkhipov/41a088998af07d66be6c to your computer and use it in GitHub Desktop.
Optional chaining inside closure
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
// http://stackoverflow.com/questions/29365781/weird-behavious-using-optionals-inside-closure | |
struct GameSettings {} | |
protocol Delegate { | |
func didFinishSettings(settings: GameSettings, controller: Controller) | |
} | |
class Controller { | |
init() {} | |
var delegate: Delegate? | |
func setUpSettingsForNextGame( | |
successCompletion:(settings:GameSettings)->Void) | |
{} | |
func f2() { | |
setUpSettingsForNextGame {[weak self] (settings:GameSettings) in | |
if let delegate = self?.delegate { | |
delegate.didFinishSettings(settings, controller:self!) | |
} | |
} | |
} | |
func f1() { | |
setUpSettingsForNextGame {[weak self] (settings:GameSettings) in | |
self?.delegate?.didFinishSettings(settings, controller:self!) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment