Reachability.swift: if .none is changed to .unavailable why it ask me to add both ?

Created on 17 Oct 2019  路  5Comments  路  Source: ashleymills/Reachability.swift

Hi ,

I noticed the last update change .none to .unavailable
that mean .none should be removed

but Xcode ask me to add both on switch !

I did do clean build but noting change untill I add both !

also
let reachability = Reachability()! is force me to remove ! and see it not optional

Cannot force unwrap value of non-optional type 'Reachability'

and after I change it to
let reachability = Reachability()

Call can throw, but errors cannot be thrown out of a property initializer

the previous version was working fine !

Most helpful comment

  • .none is only deprecated, not removed. It will be removed in a future version. In your switch statement, you can use both in the same case like: case .unavailable, .none:
  • you can use let reachability = try! Reachability() with the new version as an equivalent to let reachability = Reachability()!
  • you can also still use the old version if you need by using pinning in your dependency manager or downloading an older release from GitHub if you are using it manually

All 5 comments

let reachability = try? Reachability()
it's working for me properly.

  • .none is only deprecated, not removed. It will be removed in a future version. In your switch statement, you can use both in the same case like: case .unavailable, .none:
  • you can use let reachability = try! Reachability() with the new version as an equivalent to let reachability = Reachability()!
  • you can also still use the old version if you need by using pinning in your dependency manager or downloading an older release from GitHub if you are using it manually

@djtech42 Thanks for following up on this

Cheers
Ash

Also you have to use
NotificationCenter.default.addObserver(self, selector: #selector(self.reachabilityChanged),name: Notification.Name.reachabilityChanged,object: reachable) do{ try reachable!.startNotifier() }catch{ print("could not start reachability notifier") }

in AppDelegate didFinishLaunchingWithOptions.

Though .none is deprecated, not removed, the way we deprecated it is not appropriate.

A more suitable way is to define a static constant none and make it equal to the new case . unavailable.
And then you don't need to list .none in a switch statement anymore.

You can see the changes in PR https://github.com/ashleymills/Reachability.swift/pull/371:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

perlguy99 picture perlguy99  路  4Comments

rjt3662 picture rjt3662  路  3Comments

ShayanPapershift picture ShayanPapershift  路  3Comments

antonys1 picture antonys1  路  6Comments

sreejithsn picture sreejithsn  路  5Comments