Hi,
I tried to find explicitly in Swift documentation the behaviour of the following syntax:
For example, after
class Client {
func connect() {
// ...
let conn = NWConnection.init(to: endpoint, using: parameters)
let queue = DispatchQueue.init(label: "client")
conn.stateUpdateHandler = self.stateUpdateHandler
// ...
}
func stateUpdateHandler(_ newState: NWConnection.State) {
// ...
}
}
I assume that the stateUpdateHandler setter will retain self in that situation.
Am I right ?
I guess in this case, if the code properly cleans up the networking connection on deinit, the code should be fine (probably, the client will never be deallocated before the NWConnection).
However, is it recommended to preferably use a wrapper closure for stateUpdateHandler that explicitly define self as weak ?