Question: After I create a new swift package with dependencies I call `swift package generate-xcodeproj`. If my dependencies have a new version I call `swift package update`. The new version of my dependency gets downloaded and built but Xcode now has a bad reference to the old version of the dependency. I can call `swift package generate-xcodeproj` again but this will remove any custom targets I have setup.

How do I update my swift dependencies and my Xcode project without deleting my custom targets?

Answer: 
I just stumbled upon this question and found that the solution to "How to update swift dependencies in Xcode" has probably changed now that Swift Packages have been around for a few years.

For me, the solutions was to simply go to `File` -> `Swift Packages` -> `Update to Latest Package Versions`.

[![enter image description here](https://i.stack.imgur.com/HomP2.png)](https://i.stack.imgur.com/HomP2.png)
Instead of trying to preserve your changes to generated project, you can manage dependencies in a separate project, like CocoaPods does.

When starting new project:

1. create Xcode project for your app `MyApp.xcodeproj`
2. save as a workspace `MyApp.xcworkspace`
3. create package for your dependencies

```
mkdir MyDeps && cd MyDeps
swift package init --type library

```

4. add dependencies to `Package.swift`
5. generate Xcode project for the dependencies package

```
swift package generate-xcodeproj

```

6. add generated project `MyDeps.xcodeproj` to your workspace `MyApp.xcworkspace`
7. add target `MyDeps.framework` to Linked Frameworks of your app `MyApp.xcodeproj`

With this setup you can freely update dependencies in Package.swift and regenerate dependent project as needed.