---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# NowAttachment structure - iOS

# NowAttachment structure - iOS {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

The NowAttachment structure provides functions that enable you to
validate attachments by comparing their computed hash.
{#NowAttachmentiOSStructure__table_vx2_klw_5pb__entry__3}

| Name | Type | Description |
|-|-|-|
| data | Data | Attachment data. |
| hash | String | Computed digest for the attachment data. This computed digest is used to [validate](https://servicenow-prod.fluidtopics.net/g7KJD1~RU_nHzDzc18~DNg#NAttachiOS-validate "Validates the attachment by comparing the computed hash for the attachment data to the digest stored in the attachment metadata.") the attachment by comparing it to the known digest stored in the [attachment metadata](https://servicenow-prod.fluidtopics.net/nwJnh9cBO0AXAggTe2nkCQ#NowAttachmentMetadataiOSStructure "The NowAttachmentMetadata structure provides functions that enable you to encode and manage attachment metadata."). Calculating the computed digest is expensive; avoid using it in the UI. Instead, consider using the hash property in the [NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/nwJnh9cBO0AXAggTe2nkCQ#NowAttachmentMetadataiOSStructure "The NowAttachmentMetadata structure provides functions that enable you to encode and manage attachment metadata.") class. If you must use the computed hash, use it sparingly, and consider caching it. |
| metadata | [NowAttachmentMetadata](https://servicenow-prod.fluidtopics.net/nwJnh9cBO0AXAggTe2nkCQ#NowAttachmentMetadataiOSStructure "The NowAttachmentMetadata structure provides functions that enable you to encode and manage attachment metadata.") | Metadata associated with the attachment. |
[Table 1. Properties]

{#NowAttachmentiOSStructure__table_vx2_klw_5pb}

## NowAttachment - validate() {#ariaid-title2}

Validates the attachment by comparing the computed hash for the attachment data to the
digest stored in the attachment metadata.
{#NAttachiOS-validate__table_ovt_cgr_5pb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 2. Parameters]

{#NAttachiOS-validate__table_ovt_cgr_5pb} {#NAttachiOS-validate__table_pvt_cgr_5pb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether the attachment is valid. Possible values: * true: Attachment is valid. * false: Attachment is invalid. {#NAttachiOS-validate__ul_ohb_htf_cqb} |
[Table 3. Returns]

{#NAttachiOS-validate__table_pvt_cgr_5pb}  
The following code example shows how to call this function.

    guard 
      let metadataHeader = response.httpResponse?.value(forHTTPHeaderField: NowAttachment.attachmentMetadataHeaderKey),
      let metadataHeaderData = metadataHeader.data(using: .utf8) else {
        throw NowDataError.missingAttachmentMetadata
      }
                
    let metadata = try coder.decode(NowAttachmentMetadata.self, from: metadataHeaderData)
    let attachment = NowAttachment(metadata: metadata, data: response.data)
                
    if !attachment.validate() {
      throw NowDataError.attachmentValidation
    }
    // Attachment is valid
    return attachment


