I'm going to repost it here, since this comes up more frequently from Google, but a good path to use could be
SWIFT_PACKAGE_DIR="${BUILD_DIR%Build/*}SourcePackages/checkouts/
for the derived data checkouts, as it'll be independent of the scheme and configuration you are building, which the Build_DIR itself is not