Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Package Manager and Xcode: Retaining Xcode Settings?

I am developing a server in Swift and using the Swift Package Manager. And find it convenient when doing my development on my Mac OS system to generate a Xcode project to use Xcode as my IDE (i.e., From time to time, my package dependencies have to be updated. I've been using swift package generate-xcodeproj to do this. My problem comes in at this point-- I have created some settings in Xcode. E.g., I've set a DEBUG flag, and I have a .plist file that is in the Copy Files Phase. These get lost when I regenerate the Xcode project. It seems I cannot simply use swift package update because sometimes files change in the dependencies and these don't get propagated to the Xcode project.

What I'd like is a means to separately establish Xcode settings in a file outside of Xcode, that can be imported into Xcode when I do the swift package generate-xcodeproj. I have not seen a way to do this.

A related question is: When I do a swift build I'd like those same build settings to be used.

Suggestions?

like image 739
Chris Prince Avatar asked Jan 04 '23 19:01

Chris Prince


1 Answers

I can't help with Copy Files Phase.

However I have just been toying with conditional compilation, like this:

swift package generate-xcodeproj --xcconfig-overrides Sandbox.xcconfig

Sandbox.xcconfig

FLAG_SANDBOX = -DSANDBOX
OTHER_SWIFT_FLAGS = $(FLAG_SANDBOX)

This creates an Xcode project where SANDBOXis definded.

This can be used in swift code like this

#if SANDBOX
    print("sandbox")
#else
    print("production")
#endif
like image 165
neoneye Avatar answered Jan 17 '23 16:01

neoneye