1

CNContactStore's executeSaveRequest(_:) method throws an error according to the documentation.

I am trying to catch this error in a do/catch, but I cannot figure out what error I need to catch.

do{
  try store.executeSaveRequest(saveRequest)
} catch *???* {
  //alert the user
}

What is supposed to replace the ???'s in the code above?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
erdekhayser
  • 6,537
  • 2
  • 37
  • 69

1 Answers1

2

You have a few options actually.

Catch any error without knowing the error

catch {...}

  1. Catch any error with the specific error message

catch let error { // Use error }

  1. Use exhaustive catch clauses to handle specific errors using the CNErrorCode enum.

    enum CNErrorCode : Int {
    
        case CommunicationError
        case DataAccessError
    
        case AuthorizationDenied
    
        case RecordDoesNotExist
        case InsertedRecordAlreadyExists
        case ContainmentCycle
        case ContainmentScope
        case ParentRecordDoesNotExist
    
        case ValidationMultipleErrors
        case ValidationTypeMismatch
        case ValidationConfigurationError
    
        case PredicateInvalid
    
        case PolicyViolation
    }     
    
Community
  • 1
  • 1
Ian
  • 12,538
  • 5
  • 43
  • 62
  • Thanks! Where did you happen to find the CNErrorCodes, though? I looked all over the documentation and couldn't find them. – erdekhayser Jun 23 '15 at 15:34
  • I couldn't find them either. I just typed CNErrorCode in Xcode and command clicked it – Ian Jun 23 '15 at 15:35