Xcode 14.1 & 14.2 modifies pbxproj files automatically

With the recent update to Xcode 14.1 (also seen on Xcode 14.2), the project files get modified automatically every time it is opened. This behaviour is not seen in Xcode 13.4.1. Our project files are sorted alphabetically. Whenever the workspace or .xcodeproj is opened using Xcode 14.1 or 14.2, the pbxproj gets modified and the file references gets sorted based on the alphabetic order of the unique reference identifier as show in the below attachment. Is there a way to prevent this ? If this is a bug on the recent version of Xcode, ie 14.1 or 14.2, could you please acknowledge and address this in the next version ?

Replies

Our project files are sorted alphabetically.

It’s not clear what you mean: are you just manually sorting the files in your target’s Build Phases → Compile Sources list in Xcode? By my experiment in 14.2, hand sorting that list still works correctly and persists as expected.

Or are you modifying the underlying .pbxproj file outside of Xcode? I imagine Apple’s response would be something like: don’t do that because it’s not supported.

I suspect the latter since your screenshot shows the PBXBuildFile section of the project file. That’s not the section that defines the order of the user-visible Compile Sources list.

If you don’t modify the project file outside of Xcode, do you still experience unwanted changes to the file every time it is opened?

@Scott Thanks for your response. We have a custom script which is added as part of Post-actions under Scheme -> Build. This iterates over all the .pbxproj using xUnique and applies sorts the modified files.

Interesting utility there. My first advice would be to just remove it. Does your project actually suffer the sort of merge conflicts that xUnique claims to address? It mentions conflicts due to the same file being added on different machines, but that sounds like a larger process problem. There are definitely lots of large teams and large apps that get by fine using robust branching strategies and plain old Xcode.

Or if you do still need it, then you probably need to modify xUnique to sort the way Xcode now does. Maybe see if the original author still plans to maintain it even after all these years.

It looks like the way Xcode sorts file references changed in Xcode 14.*. I don't see any conflicts when my project is opened with Xcode 13.4.1 Also, xUnique claims to fix few other issues related to PBXBuildFile & SPM but it's not working for me. We may have to get rid of xUnique. Thanks @Scott for your inputs.