Reputation: 6657
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
Reputation: 12768
You have a few options actually.
Catch any error without knowing the error
catch {...}
catch let error { // Use error }
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