add-to-xcode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAdd to Xcode
向Xcode添加文件
⚠️ MANDATORY: Run After Creating Source Files
⚠️ 强制要求:创建源文件后必须运行
Every time you create a , , , , , or file in an Xcode project, you MUST run:
.swift.m.mm.c.cpp.hbash
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
每次在Xcode项目中创建、、、、或文件时,你必须运行:
.swift.m.mm.c.cpp.hbash
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb <filepath>如果跳过此步骤:
- ❌ 文件不会在Xcode的导航器中显示
- ❌ 文件无法随应用一起编译
- ❌ 用户必须手动添加该文件
Quick Reference
快速参考
bash
undefinedbash
undefinedALWAYS do this after creating any source file:
创建任何源文件后务必执行此操作:
Use subshell to get latest version (handles multiple cached versions)
使用子shell获取最新版本(处理多个缓存版本)
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
---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 |
|---|---|
| ✅ Yes |
| ✅ Yes |
| ✅ Yes |
| ✅ Yes |
| ✅ Yes |
| ❌ No (reference only) |
| 扩展名 | 是否加入编译源文件 |
|---|---|
| ✅ 是 |
| ✅ 是 |
| ✅ 是 |
| ✅ 是 |
| ✅ 是 |
| ❌ 否(仅作为引用) |
Workflow
工作流程
Step 1: Create the file normally
步骤1:正常创建文件
bash
undefinedbash
undefinedExample: Create a new Swift file
示例:创建一个新的Swift文件
cat > Sources/Features/MyFeature.swift << 'EOF'
import Foundation
class MyFeature {
// Implementation
}
EOF
undefinedcat > Sources/Features/MyFeature.swift << 'EOF'
import Foundation
class MyFeature {
// 实现代码
}
EOF
undefinedStep 2: Add to Xcode project
步骤2:添加到Xcode项目
bash
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb Sources/Features/MyFeature.swiftOutput:
✓ Added Sources/Features/MyFeature.swift to MyApp.xcodeproj (target: MyApp)bash
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb Sources/Features/MyFeature.swift输出:
✓ Added Sources/Features/MyFeature.swift to MyApp.xcodeproj (target: MyApp)What the Script Does
脚本功能说明
- Finds the - Searches current directory and parents
.xcodeproj - 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) are added to the first target's compile sources.cpp
- 查找文件 - 搜索当前目录及父目录
.xcodeproj - 创建组层级结构 - 与文件的目录结构保持一致
- 添加文件引用 - 在项目中注册文件
- 添加到构建目标 - 源文件(、
.swift、.m、.mm、.c)会被添加到第一个目标的编译源列表中.cpp
Requirements
环境要求
Ruby with the gem:
xcodeprojbash
gem install xcodeproj安装了 gem的Ruby环境:
xcodeprojbash
gem install xcodeprojExamples
示例
Adding a new Swift file
添加新的Swift文件
bash
undefinedbash
undefinedCreate the file
创建文件
cat > MyApp/ViewModels/ProfileViewModel.swift << 'EOF'
import SwiftUI
@Observable
class ProfileViewModel {
var name: String = ""
var email: String = ""
}
EOF
cat > MyApp/ViewModels/ProfileViewModel.swift << 'EOF'
import SwiftUI
@Observable
class ProfileViewModel {
var name: String = ""
var email: String = ""
}
EOF
Add to Xcode
添加到Xcode
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/ViewModels/ProfileViewModel.swift
undefinedruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/ViewModels/ProfileViewModel.swift
undefinedAdding a header file
添加头文件
bash
undefinedbash
undefinedCreate header
创建头文件
cat > MyApp/Bridge/MyApp-Bridging-Header.h << 'EOF'
#import <SomeLibrary/SomeLibrary.h>
EOF
cat > MyApp/Bridge/MyApp-Bridging-Header.h << 'EOF'
#import <SomeLibrary/SomeLibrary.h>
EOF
Add to Xcode (headers are added but not to compile sources)
添加到Xcode(头文件会被添加但不会加入编译源)
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Bridge/MyApp-Bridging-Header.h
undefinedruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Bridge/MyApp-Bridging-Header.h
undefinedAdding Objective-C files
添加Objective-C文件
bash
undefinedbash
undefinedCreate implementation
创建实现文件
cat > MyApp/Legacy/LegacyManager.m << 'EOF'
#import "LegacyManager.h"
@implementation LegacyManager
// Implementation
@end
EOF
cat > MyApp/Legacy/LegacyManager.m << 'EOF'
#import "LegacyManager.h"
@implementation LegacyManager
// 实现代码
@end
EOF
Add to Xcode
添加到Xcode
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Legacy/LegacyManager.m
undefinedruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb MyApp/Legacy/LegacyManager.m
undefinedAgent Integration
Agent集成
When working in an Xcode project, agents should:
- Check for before creating source files
.xcodeproj - Create the file using standard file creation
- Run add_to_xcode.rb immediately after file creation
bash
undefined在Xcode项目中工作时,Agent应遵循以下步骤:
- **创建源文件前检查**是否存在
.xcodeproj - 使用标准方式创建文件
- 创建文件后立即运行add_to_xcode.rb
bash
undefinedPattern for agents:
Agent遵循的流程:
1. Create file
1. 创建文件
cat > NewFile.swift << 'EOF'
// content
EOF
cat > NewFile.swift << 'EOF'
// 文件内容
EOF
2. Register with Xcode
2. 在Xcode中注册文件
ruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb NewFile.swift
undefinedruby ${CLAUDE_PLUGIN_ROOT}/skills/add-to-xcode/scripts/add_to_xcode.rb NewFile.swift
undefinedTroubleshooting
故障排除
"No .xcodeproj found"
提示“未找到.xcodeproj文件”
- Make sure you're running from within the Xcode project directory or a subdirectory
- 确保你在Xcode项目目录或其子目录中运行脚本
"gem not found: xcodeproj"
提示“未找到gem:xcodeproj”
- Install with:
gem install xcodeproj - On macOS with system Ruby, you may need:
sudo gem install xcodeproj
- 执行以下命令安装:
gem install xcodeproj - 在使用系统Ruby的macOS上,可能需要:
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 () are not added to compile sources (this is correct)
.h
- 检查文件扩展名是否被识别(、
.swift、.m、.mm、.c).cpp - 验证目标是否存在且包含源构建阶段
- 头文件()不会被加入编译源(这是正常现象)
.h
Related Skills
相关技能
| Skill | Use Case |
|---|---|
| Convert iOS code to Android |
| Convert Android code to iOS |
| 技能 | 使用场景 |
|---|---|
| 将iOS代码转换为Android代码 |
| 将Android代码转换为iOS代码 |