Last active
August 31, 2016 04:03
-
-
Save mikekavouras/b0639ab99d70821b8139ffc077474d80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Thing { | |
// retain cycle | |
lazy var wifi: Wifi = { | |
return Wifi { state in | |
self.onConnectionHandler(state: state) | |
} | |
}() | |
// no retain cycle | |
lazy var wifi: Wifi = { | |
return Wifi { [weak self] state in | |
self?.onConnectionHandler(state: state) | |
} | |
}() | |
} | |
// Wifi | |
class Wifi { | |
private let onConnectionHandler: (UIApplicationState) -> Void | |
init(_ connectionBlock: @escaping (UIApplicationState) -> Void) { | |
self.onConnectionHandler = connectionBlock | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment