苹果推出基于 JSON 的全新 Xcode 项目配置文件格式,用以取代传统的基于属性列表(property-list)的格式。新格式在 Xcode 27.2 中可用,旨在提升可读性、简化维护工作,并让 AI 编码智能体更容易理解和修改项目配置。
使用开源的 JSON 文件格式(xcode-project-format),在将项目配置文件提交到代码仓库后更便于校验项目配置变更,因为对比视图中的改动与 Xcode 中的操作一一对应。
新格式的一个主要优势在于,它通过提供更稳定、更可预测的项目配置表示方式降低了合并冲突的可能性。JSON 格式还让项目结构对包括 AI 编码智能体在内的自动化开发工具更加友好,简化了项目设置的检查和修改。
为帮助开发者使用这种新格式,苹果还发布了一个用于编码和解码该格式的 Swift 包。例如,以下是如何列出项目中定义的所有 target:
import XcodeProjectFormatfunc listTargets(in projectURL: URL) throws { let projectData = try Data(contentsOf: projectURL) let project = try XCSchema.Project(jsonRepresentation: projectData) for target in project.targets { print(target.name) }}
在顶层,JSON Schema 不仅定义了 target,还定义了文件树、构建配置、构建设置和外部依赖。它还支持不同子树中节点之间的关联关系。例如,一个文件可以指定它所属的构建阶段和 target。重要的是,该格式尽可能避免使用不透明的标识符,优先使用可读的名称和路径。Target 和构建产物例外,它们使用标识符来支持外部文件引用。
资深 iOS 开发者 Nikita Dyachkov 在评论此消息时指出:
合并项目文件的问题自项目文件诞生以来就一直存在,任何在多人 iOS 开发团队中工作过的人都对此深有体会。
在同一条讨论帖中,资深 iOS 工程师 Khushal Jhalani 评价这种可读性更强的新格式“大幅提升了开发体验”。不少人也认同这项改动姗姗来迟,资深 iOS 开发者 Moumita China 表示,如果早点推出,本可以免去“多年的合并冲突困扰”。
现有项目可轻松迁移,因为新格式仅改变项目在磁盘上的存储形式,底层模型不变。项目转换后,传统的 project.pbxproj 文件会替换为 project.xcproj。不过,在迁移之前请确认你正在使用的工具(包括 fastlane、CocoaPods、Tuist 等)均支持新格式。
查看英文原文:https://www.infoq.com/news/2026/10/xcode-json-project-format/
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Apple introduces a new Xcode project profile format based on JSON to replace the traditional attribute-list format. The new format is available in Xcode 27.2 and is intended to enhance readability, simplify maintenance and make it easier for AI code AI agent to understand and modify project configurations.
Using the open-source JSON file format (xcode-project-format), it is easier to verify the project configuration changes after submitting the project profile to the code repository because the changes in the contrast view correspond to operations in Xcode.
One of the main advantages of the new format is that it reduces the possibility of consolidating conflicts by providing more stable and predictable project representation. The JSON format also makes the project structure more user-friendly to automated development tools, including AI code AI agent, and streamlines the inspection and modification of project settings.
To help developers use this new format, Apple also has a Swift package for coding and decorating the format. For example, the following is a list of all targets defined in the project:
import XcodeProjectFormatfunc listTargets(in projectURL: URL) throws { let projectData = try Data(contentsOf: projectURL) let project = try XCSchema.Project(jsonRepresentation: projectData) for target in project.targets { print(target.name) }}
At the top, JSON Schema defines not only the target, but also the file tree, build configuration, build settings and external dependence. It also supports linkages between nodes in different subtrees. For example, a file can specify the construction phase and target to which it belongs. Importantly, the format avoids, to the extent possible, the use of non-transparent identifiers and gives priority to readable names and paths. With the exception of Target and build products, they use identifiers to support external document references.
Commenting on the news, senior iOS developer Nikita Dyachkov says:
The problem of consolidating project documents has existed since the inception of the project document and is well known to anyone who has worked in multiple iOS development teams.
In the same discussion point, senior iOS engineer Khushal Jhalani evaluated this new, more readable format as “a significant improvement in the development experience”. A number of people agreed with the lateness of the change, and senior iOS developer Moumita China said that if it had been introduced earlier, it would have been free of “years of conflict of integration”.
Existing projects can be easily migrated, as the new format only changes the storage of the project on disks and the bottom model remains unchanged. The traditional project.pbxproj file is replaced with project.xcproj. However, please confirm that the tools you are using (including fastlane, CocoaPods, Tuist, etc.) support the new format before moving.
See the original English language version at https://www.infoq.com/news/226/10/xcode-json-project-format/
Auto-fetched and translated by AI Atlas. All rights belong to the original author.