Issue with Reachability.m in Swift 2

Hello.


Updated to xCode 7 and swift 2 and now cannot implement the Reachability functionality in my application. Using the following code to check the status of connection:


func statusChangedWithReachability(currentReachabilityStatus: Reachability)
    {
        var networkStatus : NetworkStatus = currentReachabilityStatus.currentReachabilityStatus()
        var statusString : String = ""
        print("Network Status value: \(networkStatus.value)")
       
        if networkStatus.value == NotReachable.value    {
            print("Network Not Reachable...")
            reachabilityStatus = kNOTREACHABLE
        }
        else if networkStatus.value == ReachableViaWiFi.value  {
            print("Reachable via WIFI...")
            reachabilityStatus = kREACHABLEWITHWIFI
        }
        else if networkStatus.value == ReachableViaWWAN.value  {
            print("Reachable via WWAN...")
            reachabilityStatus = kREACHABLEWITHWWAN
        }
       
    }


Against each networkStatus.value have an error: "Value of type 'NetworkStatus' has no member 'value'." How should I implement this function in Swift 2?


Thanks a lot!

It is '.rawValue.'


Problem solved. Sorry.

If you're looking for a Swift native Reachability implementation, you could try https://github.com/ashleymills/Reachability.swift

Swift 2.1 has changed two things in imported C-enum treatment.

New Features in Xcode 7.1 Release Notes

Swift

Enums imported from C now automatically conform to the

Equatable
protocol, including a default implementation of the
==
operator. This conformance allows you to use C enum pattern matching in
switch
statements with no additional code. (17287720)

Swift Standard Library

All enums imported from C are

RawRepresentable
, including those not declared with
NS_ENUM
or
NS_OPTIONS
. As part of this change, the value property of such enums has been renamed
rawValue
. (18702016)


You have no need to use rawValue (or value) property, and can compare two enum values directly:

    func statusChangedWithReachability(currentReachabilityStatus: Reachability) {
        var networkStatus : NetworkStatus = currentReachabilityStatus.currentReachabilityStatus()
        var statusString : String = ""
        print("Network Status value: \(networkStatus)")
       
        if networkStatus == NotReachable {
            print("Network Not Reachable...")
            reachabilityStatus = kNOTREACHABLE
        }
        else if networkStatus == ReachableViaWiFi  {
            print("Reachable via WIFI...")
            reachabilityStatus = kREACHABLEWITHWIFI
        }
        else if networkStatus == ReachableViaWWAN  {
            print("Reachable via WWAN...")
            reachabilityStatus = kREACHABLEWITHWWAN
        }
       
    }
Issue with Reachability.m in Swift 2
 
 
Q