PencilKit with AI agents
Use PencilKit to capture Apple Pencil or finger input as a drawing and display it in your app. Add a PKCanvasView to your view hierarchy, observe a PKToolPicker so the canvas follows the selected tool, and store or export the resulting PKDrawing. The tool picker does not display in Mac Catalyst apps. Look up Apple's PencilKit docs first.
Last updated:
Apple facts are from "PencilKit", "PKCanvasView", "PKToolPicker", "PKDrawing", "PKCanvasViewDelegate", "setVisible(_:forFirstResponder:)" and "allowsFingerDrawing" on developer.apple.com. Tool facts are from each README. Stars as of 19 Nov 2026.
What Apple documents
PencilKit captures touch and Apple Pencil input as a drawing, and displays that content from your app. Apple’s overview says it makes it easy to incorporate hand-drawn content into your iPadOS or macOS apps, and that it provides a drawing environment for your iOS app that receives input from Apple Pencil or the user’s finger and turns it into images you display in iPadOS, iOS, or macOS. The environment comes with tools for creating, erasing, and selecting lines. It is documented for iOS 13, iPadOS 13, Mac Catalyst 13, macOS 10.15 and visionOS 1. Follow PencilKit.
Capture content with a
PKCanvasViewintegrated into your existing view hierarchy. Apple describes it as a view that captures Apple Pencil input and displays the rendered results in an iOS app. It supports low-latency capture of touches from Apple Pencil or a finger. The canvas sends final results as aPKDrawingobject, whose contents you can save with your app’s content, and you can convert the drawn content into an image for display in an iOS or macOS app. Apple’sPKCanvasViewoverview also says the canvas stores captured input in aPKDrawingReference.PKCanvasViewis a scroll view, so you can make the drawable area bigger than the canvas view’s frame by setting the inheritedcontentSize. The canvas automatically scales its underlying content to match. Users scroll around the canvas using a two-finger pan gesture. IfallowsFingerDrawingisfalse, users scroll with only one finger. ImplementPKCanvasViewDelegateto monitor drawing-related changes, includingcanvasViewDrawingDidChange(_:),canvasViewDidBeginUsingTool(_:)andcanvasViewDidEndUsingTool(_:).A
PKToolPickeris a tool palette that displays a selection of drawing tools and colors a person can choose from. It manages a draggable palette; a person may reposition it anywhere within the current window. CallsetVisible(_:forFirstResponder:)to associate the picker with one or more views. Each window manages its own tool picker, and the window’s first responder determines its visibility.PKCanvasViewconforms toPKToolPickerObserver; adding the canvas as an observer automatically updates the current drawing tools as the user changes ink colors or line widths. Apple marks as important: the tool picker doesn’t display in Mac apps built with Mac Catalyst.PKDrawingis a structure representing the drawing information captured by a canvas view. Apple says you use drawing objects to store the data associated with your user’s drawings, save that data with the rest of your app’s content, and later create a new drawing object from the saved data (init(data:)anddataRepresentation()). You can also generate an image of the drawn content withimage(from:scale:)that you can copy to the pasteboard, save to disk, or share. Saving that image into the Photos library stays in PhotoKit with AI agents.
Rules for AGENTS.md
Code
- Use PencilKit to capture Apple Pencil or finger input as a drawing and display it in the app. Add a PKCanvasView to the existing view hierarchy.
- Associate a PKToolPicker with the canvas via setVisible(_:forFirstResponder:) and add the canvas as a PKToolPickerObserver so tools, colors and line widths stay in sync. The tool picker does not display in Mac Catalyst apps.
- Persist or reload drawings with PKDrawing (dataRepresentation() / init(data:)). Use image(from:scale:) only as a PencilKit export; PhotoKit saves stay in the PhotoKit rules, not here.
- If allowsFingerDrawing is false, users scroll the canvas with one finger. Look up Apple's PencilKit docs first.Step 1: ground the agent in Apple's PencilKit docs
Install Apple Docs MCP or Sosumi and ask it to open “PencilKit”, PKCanvasView, PKToolPicker and PKDrawing. Confirm the work is the PencilKit canvas and tool picker, not a custom Core Graphics sketch view and not a PhotoKit camera or library flow.
Step 2: add the canvas and tool picker
Have the agent add a PKCanvasView to the view hierarchy, set contentSize if the drawable area should be larger than the frame, and call setVisible(_:forFirstResponder:) on a PKToolPicker. Add the canvas as a PKToolPickerObserver. Do not expect the tool picker to appear in a Mac Catalyst app.
Step 3: store and export the drawing
Read and write PKDrawing with dataRepresentation() and init(data:). Use image(from:scale:) when the app needs an image of the drawn content. Leave any Photos-library save to the existing PhotoKit flow. Implement PKCanvasViewDelegate if the app must react when the drawing or the current tool changes.
Step 4: review the SwiftUI around the drawing UI
Run swiftui-pro on the screens that host the canvas, the tool picker chrome, or export actions. Do not replace PKCanvasView or PKToolPicker with a custom SwiftUI sketch control.
Tools compared (4)
| Tool | Best for | Agents (README) | Install (README) | License | Stars | Last push |
|---|---|---|---|---|---|---|
| Apple Docs MCP (kimsungwhee) | Look up PencilKit APIs, the canvas, tool picker and drawing types | Claude Code, Cursor, VS Code, Windsurf | claude mcp add apple-docs -- npx -y @kimsungwhee/apple-docs-mcp@latest | MIT | 1388 | 17 Mar 2026 ⚠ |
| sosumi.ai (NSHipster) | Pull PencilKit docs as Markdown | any MCP host | npx -y mcp-remote https://sosumi.ai/mcp | MIT | 492 | 13 Nov 2026 |
| ApKI (Gucky) | Route the agent to official Apple developer resources | Codex, Claude Code | npx skills add https://github.com/Gucky/ApKI --skill apki | MIT | 2 | 3 Nov 2026 |
| swiftui-pro (twostraws) | Modern SwiftUI around the canvas host and export UI | Claude Code, Cursor, Codex, Gemini | npx skills add https://github.com/twostraws/SwiftUI-Agent-Skill --skill swiftui-pro | MIT | 6589 | 26 Oct 2026 |
⚠ = no push in the last 4 weeks.
Which one to pick
Official API lookup → Apple Docs MCP or Sosumi.
A short route into Apple's current developer resources → ApKI.
SwiftUI around the drawing UI → swiftui-pro.
A prompt that keeps the agent honest
Code
Add PencilKit to this iOS app. Put a PKCanvasView in the existing view hierarchy so it captures Apple Pencil or finger input. Associate a PKToolPicker with the canvas using setVisible(_:forFirstResponder:) and add the canvas as a PKToolPickerObserver so the selected tool, color and line width stay in sync. Do not expect the tool picker to display in a Mac Catalyst app. Persist drawings with PKDrawing dataRepresentation() and init(data:). Use image(from:scale:) only to export an image of the drawing; do not invent a Photos-library save here. Look up “PencilKit”, PKCanvasView, PKToolPicker and PKDrawing in Apple's docs first.FAQ
- Which platforms does PencilKit support?
- PencilKit is documented for iOS 13, iPadOS 13, Mac Catalyst 13, macOS 10.15 and visionOS 1. Apple’s overview says it makes it easy to incorporate hand-drawn content into your iPadOS or macOS apps, and that it provides a drawing environment for your iOS app that turns Apple Pencil or finger input into images you display in iPadOS, iOS, or macOS.
- How do I capture a drawing?
- Add a `PKCanvasView` to your existing view hierarchy. Apple describes it as a view that captures Apple Pencil input and displays the rendered results in an iOS app. It supports low-latency capture of touches from Apple Pencil or a finger. The canvas is a scroll view: set `contentSize` to make the drawable area larger than the frame. If `allowsFingerDrawing` is `false`, users scroll with only one finger. The canvas sends final results as a `PKDrawing` object.
- How does the tool picker work?
- A `PKToolPicker` manages a draggable palette of drawing tools and colors. Call `setVisible(_:forFirstResponder:)` to associate it with one or more views. Each window manages its own tool picker, and the window’s first responder determines visibility. Add the `PKCanvasView` as a `PKToolPickerObserver` so the canvas updates its drawing tools automatically. Apple marks as important: the tool picker doesn’t display in Mac apps built with Mac Catalyst.
- How do I save or export a drawing?
- `PKDrawing` stores the user-drawn content from a `PKCanvasView`. Save the data with the rest of your app’s content and later recreate a drawing with `init(data:)`. `dataRepresentation()` returns a raw data representation of the rendered content. `image(from:scale:)` returns an image of a specified portion of the drawing that you can copy to the pasteboard, save to disk, or share. A Photos-library save is a PhotoKit concern, not a PencilKit API.
- Which tools should the agent use first?
- Apple Docs MCP or Sosumi, so the agent opens “PencilKit”, `PKCanvasView`, `PKToolPicker` and `PKDrawing` instead of inventing a custom sketch view or a Photos save. Add swiftui-pro for the SwiftUI around the canvas host and export UI.