xcode-project-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Xcode 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
xcodeproj
gem). Under no circumstances may you write or execute Ruby scripts.
严格禁止使用Ruby、Rails或任何Ruby gem(包括
xcodeproj
gem)。在任何情况下都不得编写或执行Ruby脚本。

2. Modern Xcode Folder Synchronization

2. 现代Xcode文件夹同步

Modern Xcode projects support folder synchronization. When adding new source code (
.swift
) 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
.pbxproj
file to add files.
现代Xcode项目支持文件夹同步。添加新的源代码(
.swift
)或资源文件时,只需将其写入磁盘上的正确目录,它们会自动被包含到Xcode项目中。切勿手动修改
.pbxproj
文件来添加文件。

3. 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
xcode_spm_setup
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。

4. Toolchain Verification

4. 工具链验证

Because this skill relies entirely on a native Swift script, you must verify the environment:
  • Run
    swift --version
    before proceeding.
  • If the Swift command is not found, you must stop and recommend the user install the Swift toolchain (e.g., via
    xcode-select --install
    on macOS), or ask if you can attempt to install it for them. Do not attempt to proceed without Swift.
由于此技能完全依赖原生Swift脚本,你必须验证环境:
  • 先运行
    swift --version
    再继续。
  • 如果找不到Swift命令,必须停止操作并建议用户安装Swift工具链(例如,在macOS上通过
    xcode-select --install
    ),或者询问是否可以尝试为他们安装。没有Swift环境不得继续操作。

5. Mandatory Linker Flags for Static Frameworks (Firebase)

5. 静态框架的强制链接器标志(Firebase)

When setting up SPM dependencies that heavily rely on internal Objective-C categories and
+load
methods (such as the Firebase iOS SDK suite), the Apple linker will aggressively strip these methods out if they are linked statically.
This causes fatal runtime crashes (e.g.,
FirebaseAuth/Auth.swift:167: Fatal error: Unexpectedly found nil
).
The provided
xcode_spm_setup
Swift script automatically injects the
-ObjC
flag to
OTHER_LDFLAGS
when adding Firebase products.
However, you should still verify it is present in the build settings if you encounter issues.
  • Failing to include this flag when adding Firebase dependencies is a critical error.

当设置严重依赖内部Objective-C分类和
+load
方法的SPM依赖项(如Firebase iOS SDK套件)时,如果以静态方式链接,Apple链接器会主动剥离这些方法。
这会导致致命的运行时崩溃(例如,
FirebaseAuth/Auth.swift:167: Fatal error: Unexpectedly found nil
)。
提供的
xcode_spm_setup
Swift脚本在添加Firebase产品时,会自动将
-ObjC
标志注入到
OTHER_LDFLAGS
中。
但如果遇到问题,你仍应验证该标志是否存在于构建设置中。
  • 添加Firebase依赖时未包含此标志属于严重错误。

Empty Directory Workflow

空目录工作流程

If you are asked to build an iOS app or configure Xcode dependencies but no
.xcodeproj
or
.xcworkspace
exists
, you MUST ask the user to create the project first:
"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
.xcodeproj
via Xcode, then proceed with the Standard Xcode Workflow below.

如果要求你构建iOS应用或配置Xcode依赖,但不存在
.xcodeproj
.xcworkspace
,你必须要求用户先创建项目:
“此目录中未找到Xcode项目。请手动创建一个空的Xcode项目,准备好后告知我。”
等待用户确认已通过Xcode创建
.xcodeproj
,然后按照下面的标准Xcode工作流程继续。

Standard Xcode Workflow

标准Xcode工作流程

Do not use raw text parsing,
sed
, or Ruby scripts to modify
.pbxproj
files directly.
Instead, execute the Swift configuration package bundled with this skill (
scripts/xcode_spm_setup
) to securely install SPM packages and link optional config files (like
GoogleService-Info.plist
).
不要使用原始文本解析、
sed
或Ruby脚本直接修改
.pbxproj
文件。
相反,执行此技能附带的Swift配置包(
scripts/xcode_spm_setup
)来安全安装SPM包并链接可选配置文件(如
GoogleService-Info.plist
)。

CRITICAL: 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.,
    11.x.y
    ) in your commands instead of hardcoded placeholders.
为确保能够使用最新功能和安全修复,始终使用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:
  1. Adding the package repository dependency (e.g.,
    https://github.com/Alamofire/Alamofire
    ).
  2. Selecting the target (e.g.,
    MyApp
    ), navigating to General > Frameworks, Libraries, and Embedded Content, and hitting the
    +
    button to explicitly link the specific product modules (e.g.,
    Alamofire
    ).
The provided
xcode_spm_setup
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项目添加Swift Package时,必须完成两个不同的步骤:
  1. 添加包仓库依赖(例如,
    https://github.com/Alamofire/Alamofire
    )。
  2. 选择目标(例如,
    MyApp
    ),导航至General > Frameworks, Libraries, and Embedded Content,点击
    +
    按钮显式链接特定产品模块(例如,
    Alamofire
    )。
提供的
xcode_spm_setup
Swift脚本会自动为你处理这两个步骤。
通过传递模块列表作为参数,它会安全地注入包依赖项,并自动将这些模块连接到主目标的Frameworks构建阶段。你无需手动链接。

Usage

使用方法

  1. Locate the package path: Find the absolute path to this skill's
    scripts/xcode_spm_setup
    directory on disk.
  2. Execute: Run the native
    swift run
    command using the signature below:
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 ...]
  1. 定位包路径:找到磁盘上此技能的
    scripts/xcode_spm_setup
    目录的绝对路径。
  2. 执行:使用以下格式运行原生
    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
--plist
flag.
bash
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。注意这里没有
--plist
标志。
bash
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

Example 2: Firebase (Requires Plist)

示例2:Firebase(需要Plist)

Adding Firebase and linking the
GoogleService-Info.plist
to the resources build phase automatically. Note: Replace
11.0.0
with the actual latest version from the releases page.
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
Note: The script is idempotent. It will automatically skip linking files or packages that are already present in the project.
添加Firebase并自动将
GoogleService-Info.plist
链接到资源构建阶段。 注意:请将
11.0.0
替换为发布页面中的实际最新版本。
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
注意:该脚本具有幂等性。它会自动跳过项目中已存在的文件或包的链接操作。