xcode-pbxproj-file-registration
DevelopmentUse when xcodebuild fails with 'cannot find in scope' after adding a .swift file outside Xcode. Register in 4 pbxproj sections.
QUICK START
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/majiayu000/claude-skill-registry/blob/HEAD/skills/development/xcode-pbxproj-file-registration/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/xcode-pbxproj-file-registration, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Xcode pbxproj Manual File Registration
Extracted: 2026-02-11 Context: Xcode プロジェクト (.xcodeproj) に新規 .swift ファイルを CLI から追加する場合
Problem
GKentei/Views/Quiz/EnhancedExplanationView.swift を作成後、xcodebuild で以下のエラー:
error: cannot find 'EnhancedExplanationView' in scope
ファイルがディスク上に存在しても、project.pbxproj に登録されていないとビルド対象にならない。
Solution
project.pbxproj の 4箇所 に新規エントリを追加する:
1. PBXBuildFile (ビルド対象登録)
UNIQUE_ID_BB /* FileName.swift in Sources */ = {isa = PBXBuildFile; fileRef = UNIQUE_ID_CC /* FileName.swift */; };
2. PBXFileReference (ファイル参照定義)
UNIQUE_ID_CC /* FileName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileName.swift; sourceTree = "<group>"; };
3. PBXGroup children (グループ内ファイル一覧)
UNIQUE_ID_CC /* FileName.swift */,
4. Sources ビルドフェーズ
UNIQUE_ID_BB /* FileName.swift in Sources */,
ID 命名規則
既存ファイルの ID パターンに合わせる。例:
AAAA000011112222BBBB0006(BuildFile)AAAA000011112222CCCC0006(FileReference)
手順
- 既存の同グループファイル(例:
QuizQuestionComponents.swift)をgrepで探す - 4箇所の挿入ポイントを特定
- 既存エントリの直前/直後に新規エントリを追加
xcodebuildで確認
When to Use
- CLI(Claude Code 等)から
.swiftファイルを新規作成した時 xcodebuildで "cannot find ... in scope" エラーが出た時.xcodeprojを使用するプロジェクト(SPM-only プロジェクトでは不要)
Gotcha
.xcodeprojが.gitignoreに入っている場合、pbxproj の変更はコミットされない。Xcode で手動追加が必要xcodebuildでシミュレータ名が重複する場合はid=UUIDで指定する