| name | add-to-xcode |
| description | REQUIRED: After creating ANY .swift, .m, .mm, .c, .cpp, or .h file in a directory containing a .xcodeproj, you MUST run add_to_xcode.rb to register it with the project. Without this step, the file will NOT appear in Xcode and will NOT compile.
|
| triggers | ["create swift file","create objective-c file","add file to xcode","new ios file","new macos file","xcode project",".swift",".xcodeproj"] |
Add to Xcode
โ ๏ธ MANDATORY: Run After Creating Source Files
Every time you create a .swift, .m, .mm, .c, .cpp, or .h file in an Xcode project, you MUST run:
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb <filepath>
If you skip this step:
- โ File will NOT appear in Xcode's navigator
- โ File will NOT compile with the app
- โ User will have to manually add it
Quick Reference
ruby "$(ls -1d ~/.claude/plugins/cache/michaelboeding-skills/skills/*/skills/add-to-xcode/scripts/add_to_xcode.rb 2>/dev/null | sort -V | tail -1)" NewFile.swift
Supported File Types
| Extension | Added to Compile Sources |
|---|
.swift | โ
Yes |
.m | โ
Yes |
.mm | โ
Yes |
.c | โ
Yes |
.cpp | โ
Yes |
.h | โ No (reference only) |
Workflow
Step 1: Create the file normally
cat > Sources/Features/MyFeature.swift << 'EOF'
import Foundation
class MyFeature {
// Implementation
}
EOF
Step 2: Add to Xcode project
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb Sources/Features/MyFeature.swift
Output:
โ Added Sources/Features/MyFeature.swift to MyApp.xcodeproj (target: MyApp)
What the Script Does
- Finds the
.xcodeproj - Searches current directory and parents
- Creates group hierarchy - Matches the file's directory structure
- Adds file reference - Registers with the project
- Adds to build target - Source files (
.swift, .m, .mm, .c, .cpp) are added to the first target's compile sources
Requirements
Ruby with the xcodeproj gem:
gem install xcodeproj
Examples
Adding a new Swift file
cat > MyApp/ViewModels/ProfileViewModel.swift << 'EOF'
import SwiftUI
@Observable
class ProfileViewModel {
var name: String = ""
var email: String = ""
}
EOF
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/ViewModels/ProfileViewModel.swift
Adding a header file
cat > MyApp/Bridge/MyApp-Bridging-Header.h << 'EOF'
EOF
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Bridge/MyApp-Bridging-Header.h
Adding Objective-C files
cat > MyApp/Legacy/LegacyManager.m << 'EOF'
@implementation LegacyManager
// Implementation
@end
EOF
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Legacy/LegacyManager.m
Agent Integration
When working in an Xcode project, agents should:
- Check for
.xcodeproj before creating source files
- Create the file using standard file creation
- Run add_to_xcode.rb immediately after file creation
cat > NewFile.swift << 'EOF'
// content
EOF
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb NewFile.swift
Troubleshooting
"No .xcodeproj found"
- Make sure you're running from within the Xcode project directory or a subdirectory
"gem not found: xcodeproj"
- Install with:
gem install xcodeproj
- On macOS with system Ruby, you may need:
sudo gem install xcodeproj
File added but not compiling
- Check that the file extension is recognized (
.swift, .m, .mm, .c, .cpp)
- Verify the target exists and has a source build phase
- Header files (
.h) are not added to compile sources (this is correct)
Related Skills
| Skill | Use Case |
|---|
ios-to-android | Convert iOS code to Android |
android-to-ios | Convert Android code to iOS |