Swift and iOS/Xcode .gitignore Configuration
Complete .gitignore for Swift, iOS, and Xcode projects. Covers DerivedData, xcuserdata, CocoaPods, SPM build folder, and Xcode workspace metadata.
Detailed Explanation
Xcode and Swift projects generate substantial build caches and user-specific workspace data. A proper .gitignore is essential for teams to avoid constant merge conflicts in IDE-generated files.
Xcode build artifacts:
DerivedData/— Xcode's primary build cache. Contains compiled object files, linked binaries, index data, and module caches. This directory can easily reach several gigabytes per project. Located by default at~/Library/Developer/Xcode/DerivedData/, but some configurations place it within the project directory. Always ignore it.build/— Legacy Xcode build directory (pre-derived data era). Still used by some configurations and CI systems.*.xcarchive— Xcode archives created for App Store submission or ad-hoc distribution.
User-specific Xcode files:
*.xcuserdata/andxcuserdata/— Contains per-user breakpoints, UI layout preferences, and scheme settings. This is the number one source of merge conflicts in iOS projects. Always ignore.IDEWorkspaceChecks.plist— First-launch workspace trust dialog state.*.xccheckout— Source control metadata in Xcode workspaces.
Dependency management:
Pods/— CocoaPods dependency directory. Likenode_modules/, it is reproducible fromPodfile.lock. Always commitPodfile.lock..build/— Swift Package Manager (SPM) build directory containing fetched dependencies and compiled products.Carthage/Build/— Pre-built frameworks from Carthage.Carthage/Checkouts/is sometimes committed for reproducibility, but ignoring both is cleaner.
Other patterns:
*.dSYMand*.dSYM.zip— Debug symbol files. Important for crash symbolication but should be archived separately, not committed.*.ipa— iOS application packages. These are deployment artifacts meant for distribution.*.moved-aside— Xcode conflict resolution backup files created during merge resolution.*.hmap— Header map files used during C/Objective-C compilation.
What to commit: *.xcodeproj (the project file), *.xcworkspace (if using workspaces or CocoaPods), Podfile, Podfile.lock, Package.swift, and Package.resolved (for applications).
Use Case
An iOS team of five developers keeps having merge conflicts in xcuserdata files and needs to clean up their repository and prevent future Xcode metadata commits.