2

Can someone tell me what I'm doing wrong here? "error" is NSError returned from CloudKit.

if error.code == Int(CKErrorCode.NetworkFailure) {
    //do something
}

Gives me this error:

Binary operator '==' cannot be applied to two Int operands

If I do this, it works fine:

if error.code == 4 {
    //do something
}

Where 4 is the actual error code.

William T.
  • 12,040
  • 3
  • 52
  • 51

1 Answers1

4

The problem here is that Int doesn't have a constructor that takes CKErrorCode as input.

As in the comments, the way to compare the two values would be:

if error.code == CKErrorCode.NetworkFailure.rawValue {
    //do something
}

Thankfully, the error messages have been improved for XCode 7 and Swift 2, so you would see:

Cannot invoke initializer for type 'Int' with an argument list of type '(CKErrorCode)'

Which is a much better indicator of what went wrong.

Tom Elliott
  • 1,860
  • 1
  • 19
  • 37