Is it safe to ignore /xcuserdata/ with Git if using Launch Arguments?

XcodeGitGitignore

Xcode Problem Overview


I have an argument being passed on launch: -D DEBUG which allows me to use the following in my release app:

#ifndef DEBUG
    /* Some code I only want to be run when using the release app */
#endif

When I run git status, it shows me that the file changed when adding -D DEBUG is MyExampleProject.xcodeproj/xcuserdata/myusername.xcuserdatad/xcschemes/MyExampleProject.xcscheme

Which should be excluded using the commonly used Xcode .gitignore file. Is there any other way to include this argument that complies with .gitignore and doesn't rely on my user accounts xcuserdata?

Xcode Solutions


Solution 1 - Xcode

Generally the xcuserdata is safe to ignore for individual projects. Each user gets their own file that saves userstate, folders opened, last file opened, that sort of stuff. It does contain your schemes. If it is the first time opening and the file doesn't exist, Xcode will create it for you.

However... we have run into this issue at the office when you have a continuous build server, like Hudson or Jenkins, that copies the source from Git or SVN without ever opening it and tries to build it. If you ignore this file, there will be no schemes to build against or it will force someone to open the project to auto create it the first time.

We solved this by checking the shared box under manage schemes. This moves the schemes out from under your individual xcuserdata into a shared folder that can be committed via source control and used by the continuous build servers. Hope this helps.

Solution 2 - Xcode

This folder just contains some temporary information. Like the UI state of Xcode and similar properties. It is recommended by GitHub to exclude the xcuserdata folder in the .gitignore file.

Solution 3 - Xcode

Yes, it's safe to remove xcuserdata.

Open your pproject folder in the Finder, and right-click to "Show package contents" from .xcworkspace or .xcodeproj as appropriate. You will see 2 folders: xcshareddata and xcuserdata.

Remove xcuserdata folder and then try to open the application.

Solution 4 - Xcode

Not directly answering the question in detail, but yes it is safe since its got your username, no other developer on your project will be using your_username.xcuserdatad.

I found that Xcode (at least in 2021) puts xcuserdata it at least 3 places:

> find . -name "*xcuserdata"
./.swiftpm/xcode/package.xcworkspace/xcuserdata
./.swiftpm/xcode/xcuserdata
./project_name.xcodeproj/xcuserdata
./project_name.xcodeproj/project.xcworkspace/xcuserdata

So the easiest thing to do is add **xcuserdata to .gitignore. This is different to Github's suggestion, which was just xcuserdata.


Files in xcuserdata are non-shared scheme data and UI configuration (e.g. UserInterfaceState.xcuserstate). They are non-shared in that they belong to a user. Those settings are only read when you are the user. I don't think there's a way of you using those settings on another machine you own. I'd be interested to find out.

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsquarefrogView Question on Stackoverflow
Solution 1 - XcodeBill BurgessView Answer on Stackoverflow
Solution 2 - XcodemihoView Answer on Stackoverflow
Solution 3 - XcodeNitinView Answer on Stackoverflow
Solution 4 - XcodeBen ButterworthView Answer on Stackoverflow