skip to Main Content

Sometimes after executing git checkout branch or git reset another-branch (while Xcode is open) I find out that the Package.resolved file gets mysteriously deleted. I can easily restore it from git or just recreate it from Xcode, but it gets annoying. It seems like Xcode itself deletes it. Any idea why it happens and how to fix it?

2

Answers


  1. It appears that this is related to different versions of Swift Package Manager/XCode. Using XCode 15.3 checking out code from a different XCode version, I see that Package.resolved has been deleted, but if I go to File -> Packages -> Resolve Package Versions, I get a modified Package.resolved with the diff below, and most importantly I’m able to build successfully:

    --- a/path/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
    +++ b/path/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
    @@ -1,4 +1,5 @@
     {
    +  "originHash" : "c852dec753b6f9eeb72a53ed3e3c5dc7015d5fea756c00eff8a131987a2994d6",
       "pins" : [
         {
    @@ -271,5 +272,5 @@
           }
         }
       ],
    -  "version" : 2
    +  "version" : 3
     }
    
    
    Login or Signup to reply.
  2. Don’t switch branches or reset or anything like that with Xcode open. Just don’t do it. You can make Xcode very unhappy and Weird Stuff (tm, pat. pend.) can result. Xcode’s Git integration is extremely poor, and changing stuff on disk (like wit git switch, checkout, or reset) while Xcode has things open just confuses the heck out of Xcode. This is true even if you ordered those changes by way of the Xcode interface!

    Instead, simply close the project window, switch branches using the command line, and then open the project window. Then wait while Xcode indexes afresh, and so forth. Yes, this can take a long time. Go get a cup of coffee or something.

    One of the things Xcode will do during this preparation after you open the project window is to reconstruct the Packages.resolved file. So this should solve the issue.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search