<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 4.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PassKit",
  "identifier" : "/documentation/PassKit/PKPaymentRequest/paymentShippingAddressInvalidError(withKey:localizedDescription:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "PassKit (Apple Pay and Wallet)"
    ],
    "preciseIdentifier" : "c:objc(cs)PKPaymentRequest(cm)paymentShippingAddressInvalidErrorWithKey:localizedDescription:"
  },
  "title" : "paymentShippingAddressInvalidError(withKey:localizedDescription:)"
}
-->

# paymentShippingAddressInvalidError(withKey:localizedDescription:)

Creates a shipping address error with the supplied key and user-facing error message.

```
class func paymentShippingAddressInvalidError(withKey postalAddressKey: String, localizedDescription: String?) -> any Error
```

## Parameters

`postalAddressKey`

A key value from <doc://com.apple.documentation/documentation/Contacts/CNPostalAddress> that indicates which part of the address has an error.

`localizedDescription`

Optional. Provide a localized, user-facing error message string to help the user resolve the error.

## Discussion

You can use this convenience method to create a payment error object instead of creating an <doc://com.apple.documentation/documentation/Foundation/NSError> object yourself.  This convenience method indicates an error in the shipping address received from an Apple Pay sheet.

The error you provide and its optional message appear on the Apple Pay sheet. The available space to display messages is limited, so you should keep your messages concise.

For example, the following example shows how to create errors for indicating problems with the zip code and street, using the keys <doc://com.apple.documentation/documentation/Contacts/CNPostalAddressPostalCodeKey> and <doc://com.apple.documentation/documentation/Contacts/CNPostalAddressStreetKey>.

Creating custom errors:

```swift
// Create errors for the zip code and street address
let shippingInvalidZip = PKPaymentRequest.paymentShippingAddressInvalidError(withKey: CNPostalAddressPostalCodeKey,localizedDescription: "Invalid ZIP code")
        let shippingInvalidStreet = PKPaymentRequest.paymentShippingAddressInvalidError(withKey: CNPostalAddressStreetKey,localizedDescription: "Missing street name")
// The result contains both errors       let result = PKPaymentAuthorizationResult(status: .failure, errors: [shippingInvalidZip, shippingInvalidStreet])
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)