SwiftDate: RelativeFormatters don't work with Swift Package Manager

This is a side effect of Swift Package Manager not working with bundled resources. So, the Formatters/RelativeFormatter/langs/ various json files aren’t included and therefore aren’t accessible when using Swift Package Manager.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 15 (7 by maintainers)

Most upvoted comments

for now you can add new build phase at the end

# Go to the build root and search up the chain to find the Derived Data Path where the source packages are checked out.
DERIVED_DATA_CANDIDATE="${BUILD_ROOT}"

while ! [ -d "${DERIVED_DATA_CANDIDATE}/SourcePackages" ]; do
  if [ "${DERIVED_DATA_CANDIDATE}" = / ]; then
    echo >&2 "error: Unable to locate SourcePackages directory from BUILD_ROOT: '${BUILD_ROOT}'"
    exit 1
  fi

  DERIVED_DATA_CANDIDATE="$(dirname "${DERIVED_DATA_CANDIDATE}")"
done

# Grab a reference to the directory where langs are checked out
LANGS_PATH="${DERIVED_DATA_CANDIDATE}/SourcePackages/checkouts/SwiftDate/Sources/SwiftDate/Formatters/RelativeFormatter/langs"

if [ -z "${LANGS_PATH}" ]; then
    echo >&2 "error: Couldn't find the langs in your checked out SPM packages; make sure to add the framework to your project."
    exit 1
fi

cp -f -R "${LANGS_PATH}" "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app"

Maybe it would be possible to bring these language mappings into the swift code so that it would work properly with Swift Package Manager?

at least it should not crash 😃 ATM it crashing in suitableFlavour localeData.flavours[Flavour.long.rawValue].