xcode-project-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseXcode Project Setup
Xcode项目配置
⛔️ CRITICAL RULES & ENVIRONMENT CHECKS
⛔️ 重要规则与环境检查
Before performing any Xcode setup or file manipulation, you MUST adhere to the following rules. A hefty fee will be applied if you violate them.
在执行任何Xcode配置或文件操作之前,你必须遵守以下规则。违反规则将产生高额费用。
1. The Anti-Ruby Mandate
1. 禁用Ruby规定
You are strictly forbidden from using Ruby, Rails, or any Ruby gems (including the gem). Under no circumstances may you write or execute Ruby scripts.
xcodeproj严格禁止使用Ruby、Rails或任何Ruby gem(包括 gem)。在任何情况下都不得编写或执行Ruby脚本。
xcodeproj2. Modern Xcode Folder Synchronization
2. 现代Xcode文件夹同步
Modern Xcode projects support folder synchronization. When adding new source code () or resource files, simply write them to the correct directory on disk. They will be automatically included in the Xcode project. Never manually modify the file to add files.
.swift.pbxproj现代Xcode项目支持文件夹同步。添加新的源代码()或资源文件时,只需将其写入磁盘上的正确目录,它们会自动被包含到Xcode项目中。切勿手动修改文件来添加文件。
.swift.pbxproj3. Allowed Scripting Languages
3. 允许使用的脚本语言
If you absolutely must write a script to manipulate the project environment (e.g., configuring SPM packages beyond what the provided script does), you must use Swift. Only as an absolute last resort, if Swift is completely unviable, may you use Node.js or TypeScript.
xcode_spm_setup如果确实需要编写脚本来操作项目环境(例如,超出提供的脚本功能配置SPM包),你必须使用Swift。只有在Swift完全不可行的极端情况下,才可以使用Node.js或TypeScript。
xcode_spm_setup4. Toolchain Verification
4. 工具链验证
Because this skill relies entirely on a native Swift script, you must verify the environment:
- Run before proceeding.
swift --version - If the Swift command is not found, you must stop and recommend the user install the Swift toolchain (e.g., via on macOS), or ask if you can attempt to install it for them. Do not attempt to proceed without Swift.
xcode-select --install
由于此技能完全依赖原生Swift脚本,你必须验证环境:
- 先运行再继续。
swift --version - 如果找不到Swift命令,必须停止操作并建议用户安装Swift工具链(例如,在macOS上通过),或者询问是否可以尝试为他们安装。没有Swift环境不得继续操作。
xcode-select --install
5. Mandatory Linker Flags for Static Frameworks (Firebase)
5. 静态框架的强制链接器标志(Firebase)
When setting up SPM dependencies that heavily rely on internal Objective-C categories and methods (such as the Firebase iOS SDK suite), the Apple linker will aggressively strip these methods out if they are linked statically.
+loadThis causes fatal runtime crashes (e.g., ).
FirebaseAuth/Auth.swift:167: Fatal error: Unexpectedly found nilThe provided Swift script automatically injects the flag to when adding Firebase products. However, you should still verify it is present in the build settings if you encounter issues.
xcode_spm_setup-ObjCOTHER_LDFLAGS- Failing to include this flag when adding Firebase dependencies is a critical error.
当设置严重依赖内部Objective-C分类和方法的SPM依赖项(如Firebase iOS SDK套件)时,如果以静态方式链接,Apple链接器会主动剥离这些方法。
+load这会导致致命的运行时崩溃(例如,)。
FirebaseAuth/Auth.swift:167: Fatal error: Unexpectedly found nil提供的 Swift脚本在添加Firebase产品时,会自动将标志注入到中。 但如果遇到问题,你仍应验证该标志是否存在于构建设置中。
xcode_spm_setup-ObjCOTHER_LDFLAGS- 添加Firebase依赖时未包含此标志属于严重错误。
Empty Directory Workflow
空目录工作流程
If you are asked to build an iOS app or configure Xcode dependencies but no or exists, you MUST ask the user to create the project first:
.xcodeproj.xcworkspace"No Xcode project found in this directory. Please create an empty Xcode project manually and let me know when you are ready to proceed."
Wait for the user to confirm they have created the via Xcode, then proceed with the Standard Xcode Workflow below.
.xcodeproj如果要求你构建iOS应用或配置Xcode依赖,但不存在或,你必须要求用户先创建项目:
.xcodeproj.xcworkspace“此目录中未找到Xcode项目。请手动创建一个空的Xcode项目,准备好后告知我。”
等待用户确认已通过Xcode创建,然后按照下面的标准Xcode工作流程继续。
.xcodeprojStandard Xcode Workflow
标准Xcode工作流程
Do not use raw text parsing, , or Ruby scripts to modify files directly.
sed.pbxprojInstead, execute the Swift configuration package bundled with this skill () to securely install SPM packages and link optional config files (like ).
scripts/xcode_spm_setupGoogleService-Info.plist不要使用原始文本解析、或Ruby脚本直接修改文件。
sed.pbxproj相反,执行此技能附带的Swift配置包()来安全安装SPM包并链接可选配置文件(如)。
scripts/xcode_spm_setupGoogleService-Info.plistCRITICAL: Always Use Latest SDK Version
重要提示:始终使用最新SDK版本
To ensure access to the latest features and security fixes, always use the most recent version of the Firebase iOS SDK. Check for the latest release version at https://github.com/firebase/firebase-ios-sdk/releases.
- Use the most recent version number (e.g., ) in your commands instead of hardcoded placeholders.
11.x.y
为确保能够使用最新功能和安全修复,始终使用Firebase iOS SDK的最新版本。请访问https://github.com/firebase/firebase-ios-sdk/releases查看最新发布版本。
- 在命令中使用最新版本号(例如,),而非硬编码的占位符。
11.x.y
Understanding the Script's Actions
理解脚本的操作
When adding a Swift Package to an Xcode project, two distinct steps must occur:
- Adding the package repository dependency (e.g., ).
https://github.com/Alamofire/Alamofire - Selecting the target (e.g., ), navigating to General > Frameworks, Libraries, and Embedded Content, and hitting the
MyAppbutton to explicitly link the specific product modules (e.g.,+).Alamofire
The provided Swift script automatically handles BOTH of these steps for you. By passing the list of modules as arguments, it safely injects the package dependency and automatically wires those modules to the main target's Frameworks build phase. You do not need to do any manual linking.
xcode_spm_setup向Xcode项目添加Swift Package时,必须完成两个不同的步骤:
- 添加包仓库依赖(例如,)。
https://github.com/Alamofire/Alamofire - 选择目标(例如,),导航至General > Frameworks, Libraries, and Embedded Content,点击
MyApp按钮显式链接特定产品模块(例如,+)。Alamofire
提供的 Swift脚本会自动为你处理这两个步骤。 通过传递模块列表作为参数,它会安全地注入包依赖项,并自动将这些模块连接到主目标的Frameworks构建阶段。你无需手动链接。
xcode_spm_setupUsage
使用方法
- Locate the package path: Find the absolute path to this skill's directory on disk.
scripts/xcode_spm_setup - Execute: Run the native command using the signature below:
swift run
bash
swift run --package-path <PATH_TO_SKILL>/scripts/xcode_spm_setup xcode_spm_setup <ProjectPath.xcodeproj> <RepoURL> <VersionRequirement> [--plist <Optional/Path/To/Config.plist>] <Product1> [Product2 ...]- 定位包路径:找到磁盘上此技能的目录的绝对路径。
scripts/xcode_spm_setup - 执行:使用以下格式运行原生命令:
swift run
bash
swift run --package-path <PATH_TO_SKILL>/scripts/xcode_spm_setup xcode_spm_setup <ProjectPath.xcodeproj> <RepoURL> <VersionRequirement> [--plist <Optional/Path/To/Config.plist>] <Product1> [Product2 ...]Example 1: Generic Package (e.g., Alamofire)
示例1:通用包(如Alamofire)
Adding Alamofire to a standard Xcode project. Notice there is no flag.
--plistbash
swift run --package-path /Users/foo/.agents/skills/xcode-project-setup/scripts/xcode_spm_setup xcode_spm_setup MyApp.xcodeproj https://github.com/Alamofire/Alamofire 5.8.1 Alamofire向标准Xcode项目添加Alamofire。注意这里没有标志。
--plistbash
swift run --package-path /Users/foo/.agents/skills/xcode-project-setup/scripts/xcode_spm_setup xcode_spm_setup MyApp.xcodeproj https://github.com/Alamofire/Alamofire 5.8.1 AlamofireExample 2: Firebase (Requires Plist)
示例2:Firebase(需要Plist)
Adding Firebase and linking the to the resources build phase automatically.
Note: Replace with the actual latest version from the releases page.
GoogleService-Info.plist11.0.0bash
swift run --package-path /Users/foo/.agents/skills/xcode-project-setup/scripts/xcode_spm_setup xcode_spm_setup MyApp.xcodeproj https://github.com/firebase/firebase-ios-sdk 11.0.0 --plist MyApp/GoogleService-Info.plist FirebaseCore FirebaseAuth FirebaseFirestoreNote: The script is idempotent. It will automatically skip linking files or packages that are already present in the project.
bash
swift run --package-path /Users/foo/.agents/skills/xcode-project-setup/scripts/xcode_spm_setup xcode_spm_setup MyApp.xcodeproj https://github.com/firebase/firebase-ios-sdk 11.0.0 --plist MyApp/GoogleService-Info.plist FirebaseCore FirebaseAuth FirebaseFirestore注意:该脚本具有幂等性。它会自动跳过项目中已存在的文件或包的链接操作。