Skip to content

Instantly share code, notes, and snippets.

@mikekavouras
Last active August 31, 2016 04:03
Show Gist options
  • Save mikekavouras/b0639ab99d70821b8139ffc077474d80 to your computer and use it in GitHub Desktop.
Save mikekavouras/b0639ab99d70821b8139ffc077474d80 to your computer and use it in GitHub Desktop.
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