{
"$type": "site.standard.document",
"description": "How I make Xcode fail the build when project.yml changes but the generated Xcode project has not been regenerated with XcodeGen.",
"path": "/tweaking-xcodegen-project-to-check-xcode-project-is-not-outdated/",
"publishedAt": "2024-06-20T15:47:00.000Z",
"site": "at://did:plc:bryys25pc2fnagnyxqgsglhd/site.standard.publication/3mn26bjkkmh23",
"tags": [
"macOS Development",
"iOS Development",
"Xcode"
],
"textContent": "As I wrote previously, I finally adopted XcodeGen across my projects. One of the mistakes I sometimes make is forgetting to run xcodegen after I update project.yml. Most of the time, this is obvious, like if I'm testing or tweaking some project settings. But I find that I might miss it if I'm updating the build or version number.\n\nThis was easy to solve. I took inspiration from CocoaPods (it checks if Podfile.lock has been modified).\n\nThere are 3 parts:\n\nCOPY PROJECT.YML WHEN RUNNING XCODEGEN\n\nI use just as my command runner, but this can easily replicated with make or a shell script. In my justfile:\n\nxcodegen:\n xcodegen\n cp project.yml .project-last.yml\n\nSo instead of running xcodegen, I run just xcodegen instead.\n\nADD A BUILD PHASE SCRIPT TO CHECK IF THE COPIED FILE IS THE SAME AS PROJECT.YML\n\nAdd this to the target in project.yml:\n\n preBuildScripts:\n - name: \"[xcodegen] Check project.yml in-sync\"\n script: |\n diff project.yml \".project-last.yml\" > /dev/null\n if [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: project.yml has been modified. Run 'just xcodegen'.\" >&2\n exit 1\n fi\n basedOnDependencyAnalysis: false\n showEnvVars: false\n\nADD .PROJECT-LAST.YML TO .GITIGNORE\n\nIn .gitignore, add:\n\n## track last generated project.yml so we can check if Xcode project is in sync when building\n.project-last.yml\n\nThat's it!\n\nJust run just xcodegen whenever you want to regenerate the Xcode project and then build with Xcode as normal. If you have edited project.yml and forget to run just xcodegen and ran xcodegen instead, or forgot both and build in Xcode, it'll complain.",
"title": "Tweaking XcodeGen Project to Check Xcode Project is not Outdated",
"updatedAt": "2026-05-23T00:00:00.000Z"
}