Preventing merge conflicts with XcodeGen for your xcode project using xcodeGen and project.yml file

ODENZA
2 min readApr 14, 2022

This article, I will show you how to setup xcode project using xcodeGen and project.yml file.

Installing tools

  • xcodeGen
  • .gitignore
  • xcconfig-extractor
  • project.yml

Install xcodeGen

See detail how to install xcodeGen

Create .gitignore file

Create useful .gitignore files for your project using keyword xcode, swift, macOS in this url > https://www.toptal.com/developers/gitignore

example

# Created by https://www.gitignore.io/api/xcode
# Edit at https://www.gitignore.io/?templates=xcode
### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## User settings
xcuserdata/
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
## Xcode Patch
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
### Xcode Patch ###
**/xcshareddata/WorkspaceSettings.xcsettings
# End of https://www.gitignore.io/api/xcode

Install xcconfig-extractor

Refactor buildSettings into xcconfig file

bash <(curl -sL https://raw.githubusercontent.com/toshi0383/scripts/master/swiftpm/install.sh) toshi0383/xcconfig-extractor// check version
xcconfig-extractor --version

Next, create xcconfig file for your project

xcconfig-extractor <project_name>.xcodeproj configurations

xcconfig file will be created in configurations folder

Next, Remove xcodeproj and xcworkspace file

git rm -r --cached <filename># example
git rm -r --cached XcodeGenProject.xcodeproj/*
# for pod file
git rm -r --cached XcodeGenProject.xcworkspace/*

Create project.yml file

In Terminal, cd to your project directory
touch project.yml then, project.yml will be created.

name: <project name> 
fileGroups:
- configs
configFiles:
Debug: configurations/Debug.xcconfig
Release: configurations/Release.xcconfig
targets:
<project name>:
type: application
platform: iOS
sources: <project name>
configFiles:
Debug: configurations/<project name>-Debug.xcconfig
Release: configurations/<project name>-Release.xcconfig settings:
CURRENT_PROJECT_VERSION: 1
scheme:
testTargets:
- <project name>Tests
- <project name>UITests
<project name>Tests:
type: bundle.unit-test
platform: iOS
sources: <project name>Tests
configFiles:
Debug: configurations/<project name>Tests-Debug.xcconfig
Release: configurations/<project name>Tests-Release.xcconfig dependencies:
- target: <project name>
<project name>UITests:
type: bundle.ui-testing
platform: iOS
sources: <project name>UITests
configFiles:
Debug: configurations/<project name>UITests-Debug.xcconfig
Release: configurations/<project name>UITests-Release.xcconfig
dependencies:
- target: <project name>

--

--