How to remove some of the Swift libraries copied by Xcode?

Viewed 865

In Xcode 10, the "Copy Swift standard libraries" script is done last — after any custom build phases that may be added to the target. Hence it is not possible to create a custom build script to specifically remove Swift standard dylib files added by Xcode.

The question is, how to remove some of these standard libraries that are erroneously added by Xcode?

The reason behind it is that when Xcode 10 builds a Swift 4.2 macOS app that has a Photo Editing extension, it adds libswiftMapKit.dylib into the application bundle — even when the application does not have Maps functionality or import MapKit. This caused an App Review rejection.

1 Answers

To remove a Swift Standard Library, add a Post-Actions in the scheme. Most likely this would be an Archive post-action since archiving is typical prior to a release (upload to App Store or to re-sign using a Developer ID credential).

  1. In Xcode 10 Click Edit Scheme.
  2. In the scheme editing, expand the Archive section.
  3. Click on Post-Actions

Enter the following bash script fragment (along with any other post-actions that you may already have)

# This variable points to the `Frameworks` folder of the final application.
full_frameworks_path="${ARCHIVE_PRODUCTS_PATH}/Applications/${FRAMEWORKS_FOLDER_PATH}"
# Specify the libraries to remove, the example below removes Swift's MapKit wrapper.
rm -f "${full_frameworks_path}/libswiftMapKit.dylib

However note that this does not solve the underlying problem of the Photos App Extension actually links to libswiftMapKit.dylib — a dependency added by Xcode 10.0 regardless whether it really uses MapKit or not.

Related