一个用于处理 Xcode 文件的实用工具集合。目前在这个 SPM 项目中有两个产品。
一个可重用的库,用于处理 xcodeproj 文件。具体来说,这个库可以轻松解析 pbxproj 和 xcconfig 文件。目前还不支持 Schemes。
使用示例
let xcodeproj = try XcodeProj(autodetectInFolderAtPath: "/path/to/project/")
try xcodeproj.iterateCombinedBuildSettingsOfTargets{ target, targetName, configurationName, combinedBuildSettings in
print("\(targetName) - \(configurationName)")
/* The line below returns the resolved value of the MARKETING_VERSION build
* setting. All the rules I’m aware of (Xcode 12 beta 6) are followed,
* including but not limited to:
* - Thorough xcconfig files parsing;
* - Embedded variables like so “$(VALUE_$(VARIANT))”;
* - Resolution of variable depending on build config levels (project config, then targets);
* - Other… */
print(combinedBuildSettings["MARKETING_VERSION"])
}
注意:虽然支持解析构建配置中的参数(例如 FOO[sdk=macosx*]
),但是变量的解析目前还不考虑这些参数。
其他注意:我使用 Xcode 10 之后的变量解析方式来解析变量。您可能会看到 XcodeProj
计算的值与 Xcode 在 GUI 编辑器中显示的值之间存在差异。这是预期的;GUI 似乎仍然使用 Xcode 10 之前的算法来解析其变量。
但是,在构建时,您应该会得到与 XcodeProj
相同的值,如果不是,请提交 issue!
您可以通过在 Info.plist
文件中添加一个键,并将值设置为 $(VAR_TO_CHECK)
,然后在运行时检查 plist 中的值,来验证这些值是否相同。
请参阅 https://stackoverflow.com/a/50731052 以获取有关 Xcode 变量解析的更多信息。