/duology-recipes:recipe-two-player-gamefrom duology-recipes
Creates a complete two-player, one-phone SwiftUI game for iPhone Duo, Apple's foldable, where each player gets half the screen in every pose. Covers EvenSplit, per-half coordinate spaces, face-to-face seating, input gating, countdown, winner screen, rematch, and UI tests for the Duo simulator.
Ships in duology-recipes. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
This recipe makes a new Xcode project: a two-player race for one iPhone Duo. Each player gets half the screen. Targets appear in each half; a player taps their own. A miss locks that player out for a moment. First to the goal wins, then both tap Rematch.
The game is a placeholder. The value is the frame around it: two halves that always show, touches judged in each half's own coordinates, rules you can test on the Mac in seconds, and UI tests that pass on the Duo simulator.
Labels: measured means we ran it, on the iPhone Duo simulator (iOS 27.1, closed, outer display) unless the line names another one. Unverified means we could not check it. Everything else links to Apple. Full source list: reference/sources.md.
Use a different skill when:
duo-layout (EvenSplit) and duo-shared-screen;duo-start./duo-new recipe-two-player-game runs steps 1 to 5, but it launches to the home screen (no launch switches) and does not run the UI tests: run step 6 yourself. Run every step yourself when there is no command.
Get three values from the user, or propose them:
AppName: letters and digits, starting with a letter (it becomes a Swift type, <AppName>App). Not Tools, and not an Apple module name such as SwiftUI or Foundation;com.example.dueltap;Run the script from this skill's folder (in the plugin: ${CLAUDE_PLUGIN_ROOT}/skills/recipe-two-player-game/scripts/new-project.sh):
"${CLAUDE_PLUGIN_ROOT}/skills/recipe-two-player-game/scripts/new-project.sh" \
DuelTap com.example.dueltap ~/Developer/DuelTap
It copies template/, replaces __APP_NAME__ and __BUNDLE_ID__ in file contents and paths, checks none are left, and prints the next steps. It refuses a folder that exists and is not empty (exit 73), and bad or clashing names (exit 65) before it creates anything.
Test the rules on the Mac. Expect 0 failed:
cd ~/Developer/DuelTap && Tools/run-engine-tests.sh
Build for the Duo simulator (find its UDID with xcrun simctl list devices available | grep "iPhone Duo"):
DEVELOPER_DIR=/Applications/Xcode-27.1.app/Contents/Developer \
xcodebuild -project DuelTap.xcodeproj -scheme DuelTap \
-destination "platform=iOS Simulator,id=<UDID>" \
-derivedDataPath build/DerivedData build
Install, launch straight into a round, and screenshot both displays. Use the simulator's UDID, not booted: several simulators may be running.
DEV=/Applications/Xcode-27.1.app/Contents/Developer
DEVELOPER_DIR=$DEV xcrun simctl install <UDID> build/DerivedData/Build/Products/Debug-iphonesimulator/DuelTap.app
DEVELOPER_DIR=$DEV xcrun simctl launch --terminate-running-process <UDID> com.example.dueltap -openDuel -autoReady -countdown 0
DEVELOPER_DIR=$DEV xcrun simctl io <UDID> screenshot --display=primary build/outer.png # outer display
DEVELOPER_DIR=$DEV xcrun simctl io <UDID> screenshot --display=primary-1 build/inner.png # inner display
Only the display in use has content; the other screenshot is black. Look at the PNG before you report.
Run the UI tests: DESTINATION="id=<UDID>" Tools/run-ui-tests.sh. With no setting it uses the simulator named iPhone Duo.
Tell the user what passed, and that poses change only in Device Hub (step 6 of the checklist).
Set DEVELOPER_DIR for every xcrun and xcodebuild call when the Mac has more than one Xcode. Never run xcode-select for this.
| Path | What it holds |
|---|---|
<App>/Engine/Duel.swift | The rules: players, ready, countdown, hits, misses, lockout, time limit, winner, rematch, seeded targets. Foundation only, nonisolated, Sendable. |
<App>/Engine/PlayArea.swift, Geometry.swift | Where targets may go inside a half, clear of the fold and cameras. Own small geometry types, so the engine needs no CoreGraphics. |
<App>/Shared/EvenSplit.swift | Two equal halves: side by side when wide, stacked when tall. Same type as the gallery's and duo-layout's. |
<App>/Duel/DuelScreen.swift | The split, seating and layout direction, system overlays, idle timer, the clock task, the leave dialog. |
<App>/Duel/PlayerHalf.swift | One half: content shape, turn, touch surface, target, score bar, ready and result panels. |
<App>/Duel/DuelModel.swift | @Observable wrapper: holds the Duel, the current time, haptic counters and the haptics switch. |
<App>/Duel/GeometryBridge.swift | CGRect to engine types, and the reserved-region query. |
<App>/App/ | App entry, RootView (home or duel), launch switches. |
<App>UITests/ | Ten UI tests, pose-agnostic. |
Tools/ | run-engine-tests.sh, EngineTests/main.swift, run-ui-tests.sh. |
Project settings: iOS 26.0 deployment, Swift 6 language mode, SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor, approachable concurrency, file-system synchronized groups (new files need no project edits), iPhone and iPad, a privacy manifest that declares nothing collected. The scheme turns off parallel testing so xcodebuild doesn't clone the simulator.
Architecture, data flow and test details: references/architecture.md.
| Technique | Where | Why |
|---|---|---|
| Both halves show in every pose | Shared/EvenSplit.swift, used in DuelScreen | ArrangementView shows only its first view when the phone is closed and held sideways (measured, see duo-layout). AnyLayout keeps each half's state when the axis flips (AnyLayout). |
| Each half has its own coordinates | PlayField in PlayerHalf.swift | .coordinateSpace(.named("p1.field")) plus SpatialTapGesture(coordinateSpace:) (doc). The engine gets points in the half's own space, so top, bottom, left, right and upside down all run the same code. |
| Face to face | Player.quarterTurns(faceToFace:sideBySide:), applied by turned(_:) in PlayerHalf | The phone lies flat with one player at each far edge, so each half turns until its top edge sits on the seam: stacked, player 1's half turns upside down; side by side, each half turns a quarter toward the seam. Same rule as duo-shared-screen. Touches still arrive in the half's own coordinates (measured: testTurnedHalfStillScores stacked on the Duo; side by side on an iPhone 17 simulator, iOS 26.2, turned to landscape). |
| Touches stay in their half | .contentShape(.interaction, Rectangle()) on each half, with no gesture on it | Measured: a hit-testable layer that grew past player 2's half took player 1's taps until each half had this content shape; the target's accessibility frame stayed 56 × 56 pt. |
| Drawing stays in its half | .clipped() on each half | Clipping hides overflow. It does not limit touches (measured); the content shape does. |
| Right-to-left languages | DuelScreen pins the split to left-to-right; PlayerHalf gives the content the real direction; PlayField stays left-to-right | Player 1 keeps the top or left half in every language, as in duo-shared-screen. Measured: with the turn inside the mirrored content, each side-by-side half's top edge pointed away from the seam, so the turn sits outside it. In a mirrored field, a tap on the drawn target counted as a miss in both halves; a left-to-right field fixed it. |
| Targets stay off the fold and cameras | FoldAvoidance.playArea(in:margin:) and Engine/PlayArea.swift | Reads active .division and .occlusion regions with reservedRegions(kind:options:layoutDirectionBehavior:) behind #available(iOS 27.1, *), then keeps the biggest strip clear of them. Not yet run with an active fold (unverified). |
| Input gating | Duel.canTap(_:now:) | No taps count during the countdown, after the round, or for a player locked out after a miss. One player's lockout never blocks the other. |
| Ready and rematch per half | ReadyPanel, ResultPanel, Duel.toggleReady | Each player starts and restarts from their own half. A round starts only when both are ready. |
| Fill the screen, keep content safe | .background { … .ignoresSafeArea() } in PlayerHalf | Colour runs to the edges; the field and score bar stay inside the safe area. Apple asks games to fill the screen in every pose rather than letterbox (HIG). |
| One shared control, in one place | duel.leave in player 2's score bar, with a confirmation | Player 2's score bar sits at the edge away from the seam in every seating. |
| Game survives fold, unfold, rotate | DuelModel lives in RootView, above the split | Layout changes never recreate the game. Fold and unfold with a round running are not yet checked (unverified). |
| No accidental exits mid-game | DuelScreen | persistentSystemOverlays(.hidden), defersSystemGestures(on: .all), isIdleTimerDisabled. |
| One haptic per hit or miss, and a switch | PlayField, HomeView | sensoryFeedback(_:trigger:condition:) on per-player counters, so each event plays once. The whole phone vibrates, so both players feel every haptic; the Haptics switch on the home screen turns them off (duo-shared-screen rule 7). |
| VoiceOver | TargetView, each half a labelled container | The target is a button with an accessibility action that counts as a tap on its centre. |
Change the rules first, in Engine/Duel.swift, and test them on the Mac before you touch a view.
DuelRules defaults (goal, countdown, lockout, time limit, target size). Keep minTargetRadius at 22 or more, so targets stay at least 44 pt across.Player, Phase, toggleReady, tick and canTap. Replace what tap(_:at:in:now:) does and what spot(for:) returns. Keep the file Foundation only and every type nonisolated and Sendable.Tools/EngineTests/main.swift with check(_:_:). Pass explicit dates (at(1.5)) instead of sleeping.TargetView, ScoreBar, ReadyPanel and ResultPanel in Duel/PlayerHalf.swift; player colours in Player.tint (DuelScreen.swift).DragGesture(minimumDistance:coordinateSpace:) on the touch surface instead of the tap. Code: architecture.md.Keep these, whatever the game:
EvenSplit for the halves, never ArrangementView..contentShape on a container that holds a positioned accessibility element. Measured: with .contentShape(Rectangle()) and the tap gesture on the field, the target's accessibility frame became the whole field (382 × 261 pt instead of 56 × 56), so UI tests tapped the middle of the field and every hit counted as a miss. VoiceOver would outline the whole field too..contentShape(.interaction, Rectangle()) on each half, with no gesture there, so nothing that grows past a half takes the other player's taps. .clipped() only hides it..allowsHitTesting(false), so touches reach the touch surface and the engine judges them..position.p1.* and p2.*, so tests address a player, not a screen position.PlayField left-to-right, and give text panels the reader's direction.On the Mac: Tools/run-engine-tests.sh builds Engine/*.swift with the test program using swiftc -swift-version 6 -default-isolation MainActor, like the app target. One check runs the engine in Task.detached and uses every engine type, so a type that loses nonisolated stops compiling (measured for all 13 types). Add a line to that check for each new engine type. Measured: 63 checks, under 10 seconds.
On the simulator: Tools/run-ui-tests.sh. The tests:
-openDuel, -autoReady, -goal, -countdown, -lockout, -timeLimit, -seed, -faceToFace); a later switch overrides an earlier one;element.coordinate(withNormalizedOffset:) (doc);twoFingerTap(), act on one element). Device Hub can't send a two-finger touch either (Xcode 27 release notes).The script passes -parallel-testing-enabled NO (otherwise xcodebuild may clone the Duo simulator, and a fresh clone can take minutes to boot) and -collect-test-diagnostics never (measured: a failing run took 720 s with diagnostics on and 138 s with them off, for about 120 s of tests). For a simulator on an older iOS runtime, pass DESTINATION="id=<UDID>".
Measured: all ten pass on the closed Duo simulator (iOS 27.1). On an iPhone 17 simulator on iOS 26.2, which runs the pre-27.1 branch of the reserved-region check, a rotation check turned the app: the fields went side by side, the score survived the turn, and face to face each half turned a quarter toward the seam and scored, left-to-right and right-to-left.
Measured on the closed Duo simulator: setting XCUIDevice.shared.orientation reported the new orientation, but the app did not turn. Set pose and rotation in Device Hub, then run testBothHalvesShowInThisPose once per pose:
Tools/run-ui-tests.sh -only-testing:DuelTapUITests/DuelTapUITests/testBothHalvesShowInThisPose
It checks the split follows the window's long side, the two play fields match, and the target's frame is the circle. It saves a screenshot of each display to the result bundle; the display not in use is black.
scripts/new-project.sh; no __APP_NAME__ or __BUNDLE_ID__ left.Tools/run-engine-tests.sh prints 0 failed.xcodebuild … build succeeds for the iPhone Duo simulator with no warnings from your code.Tools/run-ui-tests.sh passes.testBothHalvesShowInThisPose and testTurnedHalfStillScores pass.-AppleTextDirection YES -NSForceRightToLeftWritingDirection YES; player 1 keeps the top or left half, text reads right to left, and hits still count.Tools/EngineTests/main.swift.references/architecture.md (opens in a new tab)scripts/new-project.sh (opens in a new tab)template/README.md (opens in a new tab)template/Tools/EngineTests/main.swift (opens in a new tab)template/Tools/run-engine-tests.sh (opens in a new tab)template/Tools/run-ui-tests.sh (opens in a new tab)template/__APP_NAME__.xcodeproj/project.pbxproj (opens in a new tab)template/__APP_NAME__.xcodeproj/project.xcworkspace/contents.xcworkspacedata (opens in a new tab)template/__APP_NAME__.xcodeproj/xcshareddata/xcschemes/__APP_NAME__.xcscheme (opens in a new tab)template/__APP_NAME__/App/LaunchOptions.swift (opens in a new tab)template/__APP_NAME__/App/RootView.swift (opens in a new tab)template/__APP_NAME__/App/__APP_NAME__App.swift (opens in a new tab)template/__APP_NAME__/Assets.xcassets/AccentColor.colorset/Contents.json (opens in a new tab)template/__APP_NAME__/Assets.xcassets/AppIcon.appiconset/AppIcon.png (opens in a new tab)template/__APP_NAME__/Assets.xcassets/AppIcon.appiconset/Contents.json (opens in a new tab)template/__APP_NAME__/Assets.xcassets/Contents.json (opens in a new tab)template/__APP_NAME__/Duel/DuelModel.swift (opens in a new tab)template/__APP_NAME__/Duel/DuelScreen.swift (opens in a new tab)template/__APP_NAME__/Duel/GeometryBridge.swift (opens in a new tab)template/__APP_NAME__/Duel/PlayerHalf.swift (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
two-player-game, iphone-duo, foldable, shared-screen, swiftui-game, xcode-project
8 skills in this plugin
/recipe-camera-studioCreates a complete SwiftUI camera studio for iPhone Duo, Apple's foldable: photos and videos with the rear camera and a self-timer, and, while the phone is open, the person being filmed sees themselves on the outer display (CameraCaptureAccessory) with the countdown or the recording time. Closed or open and flat, the controls float along the bottom or trailing edge, off the fold; folded like a book, the preview takes the left page and the controls the right; in tabletop the preview sits above the fold and the controls below it. Use when someone wants to start a new camera, photo booth, self-portrait or filming app from scratch, or runs /duo-new recipe-camera-studio. Covers AVFoundation capture on an actor (photo and movie outputs, rotation coordinators, a second mirrored preview layer), a stand-in camera that makes the simulator usable (it has no camera), an in-app gallery with ShareLink and no file dates, usage strings, a privacy manifest with Mac checks, and UI tests on the iPhone Duo simulator./recipe-finance-dashboardCreates a complete SwiftUI personal finance dashboard for iPhone Duo, Apple's foldable: balance and recent spending in one column on the closed outer display; balance, a Swift Charts spending chart and the transaction list side by side on the open inner display; an even 8-column grid with the fold as its middle gutter (DuoColumns and PaneFrames from duo-design-system); and list-detail for a transaction that survives fold and unfold. Use when someone wants to start a new finance, budgeting, banking, expenses or any dashboard app from scratch (a new Xcode project), or runs /duo-new recipe-finance-dashboard. For an existing app, use duo-design-system (grid) and duo-patterns (list-detail) instead. Covers FoldPanes reading the .division reserved region with includeInactive, one NavigationStack whose path comes from the selection, a delayed pop on unfold that keeps the margins right, money as whole cents, a Foundation-only model tested on the Mac, and UI tests that pass in any pose on the iPhone Duo simulator./recipe-kids-learningCreates a complete SwiftUI early-learning app for young children on iPhone Duo, Apple's foldable: counting, first letters and shapes, one question at a time with a spoken prompt and big answer buttons. Closed, the picture sits above the answers; open and held wide or folded like a book, the question takes the left page and the answers the right; in tabletop the picture sits above the fold and the answers below it. Use when someone wants to start a new kids, preschool or early-learning quiz app from scratch, or runs /duo-new recipe-kids-learning. Covers a parental gate (a seeded multiplication on a number pad) in front of a grown-ups area with reset and the privacy policy link, App Review guidelines 1.3 and 5.1.4 for the Kids Category, a privacy manifest with no tracking and no data collected, no networking with a Mac check that fails if it appears, AVSpeechSynthesizer prompts, VoiceOver, progress that survives folds and relaunch, a model tested on the Mac, and UI tests on the iPhone Duo simulator./recipe-media-playerCreates a complete SwiftUI video and podcast player for iPhone Duo, Apple's foldable: a library list-detail, a full-screen player whose playback survives every fold, unfold and rotation, a tabletop layout (video above the fold, the same controls below), a book layout (video leading, controls trailing), Picture in Picture, an up next card, a mini player and background audio. Use when someone wants to start a new video, podcast, course or streaming app from scratch, or runs /duo-new recipe-media-player. For an existing player, use duo-postures (tabletop media) and duo-continuity instead. Covers one AVPlayer, AVPlayerLayer and AVPictureInPictureController owned above the layout switch, FoldRegionsLayout reading the .division reserved region, NavigationSplitView selection kept in a model, an up next card inside the controls so it never sits in the fold, a Foundation-only model tested on the Mac, bundled sample clips made with ffmpeg, and UI tests that work on the iPhone Duo simulator./recipe-notes-aiCreates a complete SwiftUI notes app for iPhone Duo, Apple's foldable, with summaries from Apple's on-device model (Foundation Models): a headline, key points and to-dos per note, streamed in. Closed, the note fills the screen and the summary is one line with Details; open, flat or like a book, the note takes the left page and the summary pane the right; in tabletop the note sits above the fold and the summary below it. Use when someone wants to start a new notes, journal or writing app with AI summaries from scratch, or runs /duo-new recipe-notes-ai. Covers a @Generable result streamed into a window-owned service so a fold never restarts it, a simple summary without AI whenever the model is unavailable or fails (it fails on the simulator), Stop and labels that say what is AI, a prompt budget for the 4,096-token context, notes that never leave the device (no network, no Private Cloud Compute) with a privacy manifest and Mac checks that say so, and UI tests on the iPhone Duo simulator./recipe-readerCreates a complete SwiftUI reading app for iPhone Duo, Apple's foldable: a library shelf, then one page on the closed outer display, two facing pages split at the fold when the phone is open and held wide or folded like a book, and in tabletop the page above the fold with the page turns below it. Use when someone wants to start a new e-reader, book, story, essay or long-form reading app from scratch, or runs /duo-new recipe-reader. For an existing reader, use duo-reading instead. Covers the reading place kept as a chapter and character offset in a store above the navigation stack, TextKit 1 pagination that runs again after every fold, rotation and Dynamic Type change, ReaderLayout reading the .division reserved region, an even-column shelf split at the fold, an in-app text size menu, swipe and VoiceOver page turns, three sample books written for the template, a Foundation-only model tested on the Mac (the paginator too, through AppKit), and UI tests that work on the iPhone Duo simulator.npx claudepluginhub kimeur/duology --plugin duology-recipesOther plugins' skills for the same job