Hi,
the documentation says "isReachable has been deprecated. Use connection != .none instead".
This can cause confusion when used together with optionals. Here is an example:
Assume you store the reachability instance into an optional property:
var reachability = Reachability()
And then later you want to do something if you are not connected:
if reachability?.connection == .none {
// show offline message, for example
}
The code inside the if statement will only be called if reachability is nil, not if it has a value and connection equals .none (because Swift checks if the optional value _reachability_ equals Optional.none). To make it work when _reachability_ is an optional property, you have to write
if reachability?.connection == Reachability.Connection.none {
// show offline message, for example
}
Thats why it might be better to rename Connection.none to something else or mention it in the documentation.
@hamchapman We should look at renaming this I think鈥β營'm struggling to think of good name. Connection.noConnection
repeats "connection" so that's out. Maybe .off
?
@ashleymills @hamchapman I think Connection.unavailable
works best here.
@DanielStormApps Perfect!
Connection.unavailable
sounds good to me 馃憤
Just faced this confusion after updating - it tricked me! 馃槃
Renaming Connection.unavailable
in an upcoming release sounds great 馃憤
I encountered this issue recently. Are there plans to actually implement this fix?
I just pushed this fix - will be in the next release
Most helpful comment
Connection.unavailable
sounds good to me 馃憤