1

I am attempting to do this in Swift:

var netStatus:NetworkStatus = reachability.currentReachabilityStatus();
if (!netStatus) { // error here says network status not convertible to bool
    ....
}

typedef enum : NSInteger {
    NotReachable = 0,
    ReachableViaWiFi,
    ReachableViaWWAN
} NetworkStatus;

I've also tried

if (netStatus ==0)
if (netStatus == NetworkStatus.NotReachable) // NetworkStatus.type does not have a member named 'NotReachable'

etc.

0

3 Answers 3

3

Try using modern objective-c practices:

typedef NS_ENUM(NSInteger, NetworkStatus) {
        NetworkStatusNotReachable,
        NetworkStatusReachableViaWiFi,
        NetworkStatusReachableViaWAN
};

Adopting Modern Objective-C

Sign up to request clarification or add additional context in comments.

Comments

0

Read the Swift manual on how to define enum. it's more like

enum NetworkStatus:Int {
  case NotReachable = 0
  case Reach....
}

1 Comment

I'm assuming the enum is defined in Objective-C, hence the question on how to use Objective-C enums in Swift.
0

Unfortunately an enum is not transferrable to Swift from Objective-C, it needs to be an NS_ENUM.

If you can change the definition of the enum, then Daniel T.'s solution is best.

However, if you cannot change the enum definition, then you can create an intermediary class to provide an NS_ENUM and a mapping to the enum values.

See: https://stackoverflow.com/a/24950414/600753 for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.