1

In Swift, we need to compare the code property from a NSError object against a NSInteger value stored in a NS_ENUM.

The NS_ENUM struct (from https://github.com/piemonte/PBJVision/blob/master/Source/PBJVision.h):

typedef NS_ENUM(NSInteger, PBJVisionErrorType)
{
    PBJVisionErrorUnknown = -1,
    PBJVisionErrorCancelled = 100,
    PBJVisionErrorSessionFailed = 101,
    PBJVisionErrorBadOutputFile = 102,
    PBJVisionErrorOutputFileExists = 103,
    PBJVisionErrorCaptureFailed = 104,
};

We want to see if the error code matches PBJVisionErrorCancelled, but we can't figure out the syntax in Swift.

After reading other SO posts and exploring multiple blog posts, there were several options tried but none worked:

Int(error!.code) == Int(PBJVisionErrorType.Cancelled)
Int(error!.code) == Int(PBJVisionErrorType.Cancelled.value)
error!.code == Int(PBJVisionErrorType.Cancelled)
error!.code == Int(PBJVisionErrorType.Cancelled.value)
error!.code == PBJVisionErrorType.Cancelled.value

What's the right syntax?

Crashalot
  • 31,452
  • 56
  • 235
  • 393

0 Answers0