65

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?

mfaani
  • 33,269
  • 19
  • 164
  • 293
squarefrog
  • 4,750
  • 4
  • 35
  • 64

4 Answers4

123

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.

starball
  • 20,030
  • 7
  • 43
  • 238
Bill Burgess
  • 14,054
  • 6
  • 49
  • 86
  • No problem! We just ran across this same issue just a week ago. Glad I could help out. – Bill Burgess Dec 19 '12 at 16:12
  • yes Bill Burgess you are right once I deleted it from the bitbucket and we were working in team so it created me a lot of problems. You should never delete it if you are working in team and using source control. – Anirudha Mahale Aug 25 '16 at 11:37
  • Add the schemes to the shared list, in the scheme manager to fix this – Jonathan. Nov 29 '21 at 22:42
21

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.

miho
  • 11,765
  • 7
  • 42
  • 85
  • will this affect my use of schemes? – squarefrog Dec 19 '12 at 13:41
  • 5
    Depends on what kind of scheme. Shared schemes (see `Manage Schemes`) are stored in the project file and won't get lost, but local schemes are stored inside `xcuserdata`. – miho Dec 19 '12 at 14:45
0

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.

Joe McMahon
  • 3,266
  • 21
  • 33
Nitin
  • 497
  • 3
  • 8
0

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

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167