pencilkit
Add Apple Pencil drawing with PKCanvasView, PKToolPicker, PKDrawing serialization/export, stroke inspection, and PencilKit/PaperKit handoffs. Use when building drawing apps, annotation features, handwriting capture, signature fields, content-version-safe ink workflows, or Apple Pencil-powered experiences on iOS/iPadOS/visionOS.
Security Assessment
About pencilkit
Covers adding Apple Pencil and finger drawing to iOS, iPadOS, and visionOS apps with PencilKit, with examples targeting Swift 6.3 and iOS 26+. It suits drawing apps, annotation and handwriting capture, signature fields, and content-version-safe ink workflows. PencilKit needs no entitlements or Info.plist entries; work begins by importing PencilKit and creating a PKCanvasView, a UIScrollView subclass that captures input and renders strokes. Drawing policies (.default, .anyInput, .pencilOnly) control whether finger input draws, and the canvas exposes tool, ruler, and content-size configuration.
PKToolPicker presents a floating tool palette that the canvas adopts automatically, and PKToolPicker(toolItems:) with custom picker item classes allows a curated set of tools, requiring iOS/iPadOS 18+ (macOS 26 for those item classes). Ink types include pen, pencil, marker, monoline, fountainPen, watercolor, crayon, and reed. PKDrawing is a value type holding all stroke data; it serializes via dataRepresentation() to Data and reloads with PKDrawing(data:), and the guidance stresses handling decode failures explicitly rather than suppressing them with try?. Drawings can be appended, combined, and transformed with affine transforms, and exported to a UIImage.
Content-version compatibility is a central theme: versions one through four map to progressively newer ink and stroke features, and requiredContentVersion together with maximumSupportedContentVersion (set on both the canvas and the tool picker) gate what older clients can load and keep editing. When content exceeds a target OS version, the recommendation is to preserve the full-fidelity drawing for capable clients and provide a read-only preview or verified fallback rather than silently overwriting it. Stroke inspection, SwiftUI integration, and the PaperKit relationship are also addressed.
FAQ
What platforms and versions does PencilKit target here?
PencilKit itself runs on iOS and iPadOS 13+, Mac Catalyst 13.1+, and visionOS 1.0+, while the skill's examples target Swift 6.3 and iOS 26+.
What are the three drawing policies?
.default respects the user's Pencil-only preference when the tool picker is visible, .anyInput lets both pencil and finger draw, and .pencilOnly restricts drawing to Apple Pencil touches.
How is a drawing persisted and reloaded?
Serialize a PKDrawing with dataRepresentation() to Data and write it out, then reload with PKDrawing(data:). Decode failures should be handled explicitly with do/catch rather than suppressed with try?.
What are content versions used for?
They gate cross-version compatibility. Check requiredContentVersion and set maximumSupportedContentVersion on both the canvas and tool picker so older clients can keep editing, providing a read-only fallback when content is too new.
Does PencilKit require any special app configuration?
No. It requires no entitlements or Info.plist entries; you simply import PencilKit and create a PKCanvasView.
Install pencilkit
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
dpearson2699/swift-ios-skills