OTSubscriberErrorCode is an NS_ENUM
written in Objective-C. (Why objective-c NS_ENUM variable automatically have default value)
typedef NS_ENUM(int32_t, OTSubscriberErrorCode ) {
OTSubscriberSuccess = 0,
OTConnectionTimedOut = 1542,
OTSubscriberSessionDisconnected = 1541,
OTSubscriberWebRTCError = 1600,
OTSubscriberServerCannotFindStream = 1604,
OTSubscriberStreamLimitExceeded = 1605,
OTSubscriberInternalError = 2000,
};
You could make a Swift version of that enum like so:
enum OTSubscriberErrorCodeSwift: Int32 {
case success = 0
case timeout = 1542
case sessionDisconnected = 1541
case webRTCError = 1600
case cannotFindStream = 1604
case streamLimitExceeded = 1605
case internalError = 2000
}
So that when you attempt to make an error out of that "Swifty" enum with an invalid rawValue, you'll get nil.
let error = OTSubscriberErrorCodeSwift(rawValue: 1010) // nil
EDIT
When using Objective-C's NS_ENUM
, you could just use switch statement, like so:
let error = OTSubscriberErrorCode(rawValue: 1010)
if let error = error {
switch error {
case .subscriberSuccess: print("subscriberSuccess")
case .connectionTimedOut: print("timeout")
case .subscriberSessionDisconnected: print("subscriberSessionDisconnected")
case .subscriberWebRTCError: print("subscriberWebRTCError")
case .subscriberServerCannotFindStream: print("subscriberServerCannotFindStream")
case .subscriberStreamLimitExceeded: print("subscriberStreamLimitExceeded")
case .subscriberInternalError: print("subscriberInternalError")
default: print("NO ERROR")
}
}
In the case above, you'll get to the default. From there, do whatever you wanted to do as if the error
variable is nil.