For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: 子どもごとの完了パーティクル選択と写真アイコンを、2 つの独立した非消耗型 IAP として追加する。
Architecture:
Child に particleStyle と photoFileName を持たせる。StoreManager が StoreKit 2 の currentEntitlements から決める。ChildPhotoStore が Application Support/ChildPhotos/ に JPEG で保存する。Tech Stack: Swift / SwiftUI / StoreKit 2 / PhotosUI(PhotosPicker)/ Swift Testing。外部ライブラリは使わない。
Spec: docs/superpowers/specs/2026-11-03-v1.5.0-iap-customization-design.md(各タスクに着手する前に必ず読む)
com.tknzk.ttd.particles と com.tknzk.ttd.photoicon。どちらも Non-Consumable、familyShareable: true、$0.99。revocationDate != nil)と検証に失敗した取引は除外する。AppData には保存しない。Child.id に結びつけない(id は起動のたびに作り直される)。decodeIfPresent と既定値で読む。未知の particleStyle 値は .confetti として読む。isExcludedFromBackup は設定しない。ParentalGateView)は、購入シートを開く前に 1 回だけ出す。Localizable.strings に入れ、LocalizedString(_:comment:) で取り出す。PBXFileSystemSynchronizedRootGroup)なので、app/todo-board/ や app/todo-boardTests/ に新しく作ったファイルは自動でターゲットに入る。project.pbxproj は手で編集しない(例外はタスク 8 のバージョン番号だけ)。コマンド(app/ ディレクトリで実行する):
# テスト(iPhone 17)
xcodebuild -scheme todo-board -destination 'platform=iOS Simulator,id=C24E8EF3-A7E5-4296-A014-C78A717B4B74' test
# 一部のテストだけ
xcodebuild ... test -only-testing:todo-boardTests/<SuiteName>
particleStyle と photoFileName のキーがない v1.4.0 形式の AppData JSON を読むと、子ども・タスク・設定がすべて残っていること。デコードに失敗すると、全データがサンプルデータに置き換わってしまう。→ タスク 1photoFileName は設定されているのに、ファイルがない(バックアップからの復元漏れ、手動削除など)場合は、落ちずに名前だけを表示すること。→ タスク 2、タスク 4Files:
app/todo-board/ParticleStyle.swiftapp/todo-board/Models.swift(struct Child)app/todo-boardTests/CustomizationModelTests.swiftInterfaces:
enum ParticleStyle: String, Codable, CaseIterable, Identifiable { case confetti, stars, hearts, fireworks }
var isPremium: Bool を持つ(.confetti だけが false)。var displayNameKey: String を持つ。値は "particle.confetti" などのローカライズキー。init(from:) は、未知の値を .confetti にする。Child に次を追加する。
var particleStyle: ParticleStyle = .confettivar photoFileName: String? = nilparticleStyle と photoFileName を足し、init(from:) を自前で書く。func effectiveParticleStyle(_ style: ParticleStyle, hasParticles: Bool) -> ParticleStyle(グローバル関数。ParticleStyle.swift に置く)func effectivePhotoFileName(_ child: Child, hasPhotoIcon: Bool) -> String?(同じファイルに置く)@Suite struct CustomizationModelTests {
@Test func decodesV140ChildWithoutNewKeys() throws {
let json = #"{"name":"太郎","tasks":[{"label":"宿題","isCompleted":true}],"color":"red"}"#
let child = try JSONDecoder().decode(Child.self, from: Data(json.utf8))
#expect(child.name == "太郎"); #expect(child.tasks.count == 1)
#expect(child.particleStyle == .confetti); #expect(child.photoFileName == nil)
}
@Test func decodesV140AppDataKeepsEverything() throws // children 2 人 + hashedPIN 付きの v1.4.0 JSON を AppData としてデコードし、子どもの数・名前・hashedPIN != nil を確認する
@Test func unknownParticleStyleFallsBackToConfetti() throws {
let json = #"{"name":"a","tasks":[],"color":"blue","particleStyle":"rainbow"}"#
#expect(try JSONDecoder().decode(Child.self, from: Data(json.utf8)).particleStyle == .confetti)
}
@Test func roundTripKeepsNewFields() throws // .hearts と "abc.jpg" をエンコードしてデコードし、同じ値に戻ることを確認する
@Test func effectiveStyleWhenNotPurchased() {
#expect(effectiveParticleStyle(.fireworks, hasParticles: false) == .confetti)
#expect(effectiveParticleStyle(.fireworks, hasParticles: true) == .fireworks)
}
@Test func effectivePhotoWhenNotPurchased() // photoFileName = "x.jpg" の子どもで、hasPhotoIcon が false なら nil、true なら "x.jpg" になることを確認する
}
decodesV140AppDataKeepsEverything の JSON は、実際の v1.4.0 の AppData をエンコードした形(resetTime、languagePreference などを含む)で作る。
ChildColor の rawValue は Models.swift で確認する。
-only-testing:todo-boardTests/CustomizationModelTestsParticleStyle が未定義)。Child.init(from:) は AppData.init(from:) と同じ書き方にする。既存のキー(name、tasks、color)のデコードの厳しさは今と同じに保つ。encode(to:) は自動生成のままでよい(CodingKeys に足せば新しいフィールドも出力される)。todo_boardTests も一緒に実行する。Add ParticleStyle and per-child customization fieldsFiles:
app/todo-board/ChildPhotoStore.swiftapp/todo-boardTests/ChildPhotoStoreTests.swiftInterfaces:
@MainActor final class ChildPhotoStore
init(directory: URL)static let shared: 保存先は Application Support/ChildPhotos。func save(_ image: UIImage) throws -> String: 戻り値は "<uuid>.jpg"。保存先のディレクトリがなければ作る。func image(named fileName: String) -> UIImage?: [String: UIImage] でメモリにキャッシュする。ファイルがなければ nil を返す。func delete(named fileName: String): ファイルがなくても何もしないで終わる。キャッシュからも消す。static func processedJPEGData(from image: UIImage, side: CGFloat = 512, quality: CGFloat = 0.8) -> Data?
side×side に縮小する。UIGraphicsImageRenderer を使い、format.scale = 1 にする。imageOrientation を正しく扱う(renderer に draw させる)。FileManager.default.temporaryDirectory/UUID() を directory に渡して実行する。@Test func saveThenLoad() // save の戻り値が ".jpg" で終わること。image(named:) が nil でなく、size が 512×512(scale 1)であること
@Test func panoramaIsCroppedToSquare() // 4000×1000 の単色画像を processedJPEGData に通し、デコードした結果が 512×512 になること
@Test func tinyImageIsUpscaledWithoutCrash() // 1×1 の画像で 512×512 になること
@Test func missingFileReturnsNil() // image(named: "nope.jpg") == nil になること
@Test func deleteRemovesFileAndCache() // save → image で読み込む → delete → ファイルが存在しない、かつ image(named:) が nil になること
@Test func deleteMissingIsNoop() // 存在しない名前を delete しても落ちないこと
-only-testing:todo-boardTests/ChildPhotoStoreTestsdata.write(to:options: .atomic) で行う。Step 4: PASS することを確認する
Add ChildPhotoStore for on-device child photosFiles:
app/todo-board/StoreManager.swiftapp/todo-board/TipJarProducts.storekit(products に 2 件を追加)app/todo-board/todo_boardApp.swift(@StateObject を追加し、.environmentObject で渡す)app/todo-boardTests/StoreManagerTests.swiftInterfaces:
enum PremiumProduct: String, CaseIterable { case particles = "com.tknzk.ttd.particles", photoIcon = "com.tknzk.ttd.photoicon" }struct EntitlementSnapshot: Equatable { let productID: String; let isVerified: Bool; let revocationDate: Date? }@MainActor final class StoreManager: ObservableObject
@Published private(set) var products: [Product]: 並び順は PremiumProduct.allCases の順。@Published private(set) var unlocked: Set<String>@Published var purchaseState: TipJarManager.PurchaseState: 既存の enum を流用する。var hasParticles: Bool、var hasPhotoIcon: Boolstatic func unlockedProductIDs(from: [EntitlementSnapshot]) -> Set<String>func loadProducts() asyncfunc refreshEntitlements() async: Transaction.currentEntitlements を EntitlementSnapshot に変換してから上の関数に渡す。func purchase(_ product: Product) async: 成功したら transaction.finish() を呼び、続けて refreshEntitlements() を呼ぶ。func restore() async: AppStore.sync() のあとで refreshEntitlements() を呼ぶ。init() の中で Transaction.updates を監視する Task を起動し、更新があるたびに finish と refresh を行う。続けて初回の refreshEntitlements を行う。@Test func verifiedUnrevokedIsUnlocked() {
let ids = StoreManager.unlockedProductIDs(from: [.init(productID: PremiumProduct.particles.rawValue, isVerified: true, revocationDate: nil)])
#expect(ids == [PremiumProduct.particles.rawValue])
}
@Test func revokedIsLocked() // revocationDate: .now の場合は空集合になること
@Test func unverifiedIsLocked() // isVerified: false の場合は空集合になること
@Test func tipProductsAreIgnored() // "com.tknzk.ttd.tip.small" は結果に含まれないこと(PremiumProduct に含まれる ID だけを残す)
@Test func bothProductsUnlockIndependently() // photoicon だけの場合、hasParticles に相当する判定が false で、photo は true になること
ファミリー共有の取引は、EntitlementSnapshot に変換するときに区別しない。つまり変換のときに ownershipType で絞り込まない。このことを refreshEntitlements のコメントに書いておく。
-only-testing:todo-boardTests/StoreManagerTests.storekit に追加する 2 件は、どちらも "type": "NonConsumable"、"familyShareable": true、"displayPrice": "0.99" にする。internalID は particles と photoicon にする。StoreManagerTests と xcodebuild ... buildBUILD SUCCEEDEDStoreKitConfigurationFileReference が見つからない)。シミュレータで購入を試す前に、Xcode の Edit Scheme → Run → Options → StoreKit Configuration で TipJarProducts.storekit を選ぶ。ここは人の手作業になるので、ユーザーに依頼する。Add StoreManager and non-consumable products for v1.5.0Files:
app/todo-board/AppDataManager.swiftapp/todo-boardTests/CustomizationManagerTests.swiftInterfaces:
Child.particleStyle と Child.photoFileNameChildPhotoStoreinit(photoStore: ChildPhotoStore = .shared): 既存の init() を置き換える。デフォルト引数があるので、既存の呼び出し(AppDataManager())はそのまま使える。let photoStore: ChildPhotoStorefunc updateChildParticleStyle(at index: Int, style: ParticleStyle)func setChildPhoto(at index: Int, image: UIImage) throws
photoFileName を更新する → 古いファイルを delete する → saveData() を呼ぶ。func removeChildPhoto(at index: Int)func childPhoto(at index: Int) -> UIImage?: 購入状態は見ない。表示するかどうかの判定は View 側で行う。removeChild(at:) を変更し、削除する子どもの写真ファイルも delete する。AppDataManager(photoStore: ChildPhotoStore(directory: tmp)) を使う。@Test func updateParticleStylePersists() // 変更したあとで、新しく作った AppDataManager を loadData しても .stars が残っていること
@Test func replacingPhotoDeletesOldFile() // 1 枚目を set → ファイル名 A、2 枚目を set → ファイル名 B。A のファイルがなく、B のファイルがあること
@Test func removePhotoClearsFieldAndFile()
@Test func removingChildDeletesPhoto() // 写真を持つ子どもを removeChild すると、そのファイルが消えること
@Test func missingPhotoFileReturnsNil() // photoFileName が存在しないファイル名でも、childPhoto(at:) が nil を返し、落ちないこと
Step 2: 失敗することを確認する
guard で何もしないで返す。Add per-child particle and photo operations to AppDataManagerFiles:
app/todo-board/CelebrationParticlesView.swift(今の ConfettiPiece はここへ移す)app/todo-board/CompletionCelebrationView.swiftapp/todo-board/MainView.swift(.overlay の中、62-68 行目付近)Interfaces:
ParticleStyle と effectiveParticleStyleStoreManager.hasParticles(@EnvironmentObject)struct CelebrationParticlesView: View { let style: ParticleStyle }CompletionCelebrationView(child: Child, particleStyle: ParticleStyle): 引数を追加する。particleStyle は呼び出し側で決める。
effectiveParticleStyle(child.particleStyle, hasParticles: store.hasParticles) を渡す。CelebrationParticlesView を実装する
confettiView と同じ見た目を保つ。#Preview を 4 種類分用意する。CompletionCelebrationView のパーティクルの層を差し替える
if !reduceMotion { CelebrationParticlesView(style: particleStyle) } にする。@EnvironmentObject var storeManager: StoreManager を追加する。#Preview と、todo_boardApp 以外で MainView を作っている箇所にも、.environmentObject(StoreManager()) を足す。BUILD SUCCEEDED、全テスト PASS。CelebrationParticlesView の #Preview で確認する。Add selectable celebration particles (stars, hearts, fireworks)Files:
app/todo-board/ChildAvatarView.swiftapp/todo-board/MainView.swift(ChildTaskView の名前 Text、182 行目付近)Interfaces:
effectivePhotoFileNameappDataManager.childPhoto(at:)StoreManager.hasPhotoIconstruct ChildAvatarView: View { let image: UIImage; let color: Color; var size: CGFloat = 44 }
color の枠線(太さ 3)を付ける。.accessibilityHidden(true))。名前の Text がすでに読み上げられるため。ChildAvatarView と、ChildTaskView の HStack(spacing: 10) { avatar?; Text(child.name) } を実装する
effectivePhotoFileName(child, hasPhotoIcon:) が nil ではないこと、かつ childPhoto(at: childIndex) が nil ではないこと。Text だけを出す。Step 2: ビルドと全テストを実行する
B353A4BC-4554-4B2E-A946-587F6D8AA4F8)の 2 列レイアウトでも崩れないことを確認する。Show child photo icon next to name on main screenFiles:
app/todo-board/PremiumStoreView.swiftapp/todo-board/SettingsView.swift
premiumSection を追加する。showingParentalGate の流れを、行き先を指定できる形に広げる。app/todo-board/en.lproj/Localizable.strings、app/todo-board/ja.lproj/Localizable.stringsInterfaces:
products、unlocked、purchase、restore)updateChildParticleStyle、setChildPhoto、removeChildPhoto、childPhotoCompletionCelebrationView(child:particleStyle:)ChildAvatarViewstruct PremiumStoreView: View
TipJarView に合わせる。enum GatedDestination { case tipJar, premiumStore } を作る。@State private var pendingGatedDestination: GatedDestination? を持つ。ParentalGateView を通ったら、その行き先のシートを開く。PremiumStoreView と premiumSection を作る
.premiumStore を行き先にして保護者確認を出す。Picker(.menu) にする。未購入のときは、premium のスタイルの横に lock.fill を出す。.premiumStore を行き先にして保護者確認を出す。
set の中で、isPremium && !hasParticles かどうかを判定する。confirmationDialog を開き、4 種類を並べる(鍵は付けない)。CompletionCelebrationView(child:particleStyle:) に渡し、オーバーレイで表示する。ChildAvatarView のサイズ 32)を出す。PhotosPicker(selection:matching: .images) を置く。選ばれた PhotosPickerItem は loadTransferable(type: Data.self) で読み、UIImage にして setChildPhoto に渡す。removeChildPhoto を呼ぶ。.premiumStore の保護者確認を出す。premium.* と particle.* にする。ja と en の両方に入れる。TipJarProducts.storekit を使う。Add premium store sheet and per-child particle/photo settingsFiles:
app/todo-board.xcodeproj/project.pbxproj(MARKETING_VERSION の 6 か所を 1.4.0 → 1.5.0 に変える。CURRENT_PROJECT_VERSION は既存の運用に従う)Modify: handoff.md(v1.5.0 の節を追加する。内容は ASC で作る IAP 2 件、審査提出の注意、確認済みの項目)
sed -i '' 's/MARKETING_VERSION = 1.4.0;/MARKETING_VERSION = 1.5.0;/' app/todo-board.xcodeproj/project.pbxprojgrep -c "MARKETING_VERSION = 1.5.0" の結果が 6 であることを確認する。2452C458-62B1-413C-A308-57E728C26153)・iPad でビルドする
BUILD SUCCEEDED。Bump version to 1.5.0