Reachability.swift icon indicating copy to clipboard operation
Reachability.swift copied to clipboard

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

Open X901 opened this issue 5 years ago • 4 comments

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 !

X901 avatar Oct 17 '19 07:10 X901

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

kosalpen11 avatar Oct 18 '19 05:10 kosalpen11

  • .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 avatar Nov 07 '19 16:11 djtech42

@djtech42 Thanks for following up on this

Cheers Ash

ashleymills avatar Nov 08 '19 08:11 ashleymills

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.

NirajCapermint avatar Feb 24 '20 12:02 NirajCapermint

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:

ShivaHuang avatar Nov 06 '20 09:11 ShivaHuang