<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PDFKit",
  "identifier" : "/documentation/PDFKit/PDFAnnotation/setValue(_:forAnnotationKey:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "PDFKit"
    ],
    "preciseIdentifier" : "c:objc(cs)PDFAnnotation(im)setValue:forAnnotationKey:"
  },
  "title" : "setValue(_:forAnnotationKey:)"
}
-->

# setValue(_:forAnnotationKey:)

Sets a value in the annotation’s dictionary.

```
func setValue(_ value: Any, forAnnotationKey key: PDFAnnotationKey) -> Bool
```

## Parameters

`value`

The value to set in the attribute’s dictionary.

`key`

A [`PDFAnnotationKey`](/documentation/PDFKit/PDFAnnotationKey) or appropriate string from the Adobe PDF Specification.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the value sets successfully; otherwise, <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Some keys expect a complex type. For example, the [`color`](/documentation/PDFKit/PDFAnnotationKey/color) key expects an array of zero, one, two, three, or four elements, where each element is a floating-point number from `0.0` to `1.0`. As a convenience, this key accepts an <doc://com.apple.documentation/documentation/AppKit/NSColor> or <doc://com.apple.documentation/documentation/UIKit/UIColor> value. For details about other conveniences, see the individual [`PDFAnnotationKey`](/documentation/PDFKit/PDFAnnotationKey) properties or the `PDFAnnotationUtilities.h` header file.

> Tip:
> Set the `PDFKIT_LOG_ANNOTATIONS` environment variable to log key-value assignment failure details.

---

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)