swiftxcodeerror-handlingenumsckerror

After updating to Xcode 8 beta 6, lost CKErrorCode and .rawValue from associated enums


I had a switch statement in Xcode 7.3 that (after passing error: NSError as an argument) worked like so:

if let code:CKErrorCode = CKErrorCode(rawValue: error.code) {
    switch code {
    case .NotAuthenticated: etc...
    }
}

After migrating to Swift 3.0 in Xcode 8 beta 6, I started getting errors saying that CKErrorCode is not recognized. I'm still importing cloud, and the migration lowercased my enums and I've tried to change it like so:

switch error.code {
case .notAuthenticated.rawValue: etc...
}

but that also seems to error (the beta seems to be buggy on my system so the errors keep disappearing and reappearing, so it's hard to tell as I code now and it may just be my system, but they persist when I compile). I've been scanning https://swift.org/migration-guide/#known-migration-issues and https://swift.org/migration-guide/ but haven't found anything yet and when I google CKErrorCode the documentation (which I'm assuming is ignoring Swift 3 since it's in beta) seems to say my previous syntax is kosher.

Can anyone point me in the right direction on this? Did enums lose .rawValue? Enums seemed to have changed, but I'm having difficulty finding documentation on what I should be doing. Is there an alternative to CKErrorCode that will recognize these enum cases? Please don't tell me cloud kit error handling changed more dramatically than that :) Thanks in advance.


Solution

  • Conversion to CKError from NSError as shown below:

    let nsError: NSError = NSError() // NSError variable. 
    
    let cError = CKError(_nsError: nsError)
    
    let cErrorCode = cError.code