---
title: "setValue(_:forAnnotationKey:)"
framework: pdfkit
role: symbol
role_heading: Instance Method
path: "pdfkit/pdfannotation/setvalue(_:forannotationkey:)"
---

# setValue(_:forAnnotationKey:)

Sets a value in the annotation’s dictionary.

## Declaration

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

## Parameters

- `value`: The value to set in the attribute’s dictionary.
- `key`: A doc://com.apple.pdfkit/documentation/PDFKit/PDFAnnotationKey or appropriate string from the Adobe PDF Specification.

## Return Value

Return Value true if the value sets successfully; otherwise, false.

## Discussion

Discussion Some keys expect a complex type. For example, the 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 NSColor or UIColor value. For details about other conveniences, see the individual PDFAnnotationKey properties or the PDFAnnotationUtilities.h header file. tip: Set the PDFKIT_LOG_ANNOTATIONS environment variable to log key-value assignment failure details.

## See Also

### Modifying Annotation Attributes

- [annotationKeyValues](pdfkit/pdfannotation/annotationkeyvalues.md)
- [value(forAnnotationKey:)](pdfkit/pdfannotation/value(forannotationkey:).md)
- [setBoolean(_:forAnnotationKey:)](pdfkit/pdfannotation/setboolean(_:forannotationkey:).md)
- [setRect(_:forAnnotationKey:)](pdfkit/pdfannotation/setrect(_:forannotationkey:).md)
- [removeValue(forAnnotationKey:)](pdfkit/pdfannotation/removevalue(forannotationkey:).md)
- [PDFAnnotationKey](pdfkit/pdfannotationkey.md)
