erdekhayser
erdekhayser

Reputation: 6657

CNContactStore Save Error

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?

Upvotes: 1

Views: 497

Answers (1)

Ian
Ian

Reputation: 12768

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
    }     
    

Upvotes: 2

Related Questions