SwiftDate
SwiftDate copied to clipboard
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.
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].
Gonna bump this. Is there a reason SwiftDate isn't working with bundled resources in SPM?
Yeah, it is my understanding that SPM doesn't currently support having bundled resources.
could some kindof "Run script" phase would help as a temp fix?
I don’t believe so. My understanding is that the resource files need to be codified.
Maybe if there was some script that you could tell the locales you wanted to support and it would copy the right codified files into place before the build. I am not sure how you would tie a script like this into the SPM build process. But might be worth looking into.
I was more thinking about app "Build Phase" "Run Script" that you have to add manually as a workaround
As stated by @drewdeponte why not take into consideration the move from json files into swift files? I don't know if it is possible to do that, but while we wait the implementation of bundled resources into SPM it may be one possible solution. Furthermore I agree on the fact that the library should not crash if can't find a particular locale. I would like the user to be able to choose which locales to include and have a default language in case some are missing.
Update on SPM bundled resources: there is (as of this week) an official proposal now available for community comment.
Regardless, I agree with @robcas3 and @drewdeponte, the library shouldn't crash when a resource is missing. That seems like a doable fix.
Moving from those JSON files to Swift is quite the undertaking... Could that also hinder localization updates or additions?
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"
I'm getting this error when running unit tests on Xcode 12, it seems to be related to the same issue:
Details: Error: Mismatch between existing container extension: <DVTExtension 0x7fc7aa5a49d0: Swift Package Folder (Xcode.IDEFoundation.Container.SwiftPackageFolder) from com.apple.dt.IDE.IDESwiftPackageSupport> and requested container extension: <DVTExtension 0x7fc7ad1b6800: Folder (Xcode.IDEFoundation.Container.Folder) from com.apple.dt.IDEFoundation> for file path: <DVTFilePath:0x7fc7b1d824f0:'/Users/mkalatrash/Library/Developer/Xcode/DerivedData/Travel-bavpgrmwbxqafacvgowqxhoryoeq/SourcePackages/checkouts/SwiftDate/Sources/SwiftDate/Formatters/RelativeFormatter/langs'>
Object: <IDEContainer>
Method: +_retainedContainerAtFilePath:fileDataType:workspace:options:error:
Thread: <NSThread: 0x7fc7ad207c60>{number = 1, name = main}
Hints:
If I run unit tests through Xcode it will crash, the above is from the command line. @RolandasRazma I did add the run script but it didn't work.
Should we just not attempt to use SPM with SwiftDate ? Or is it only an issue under certain scenarios ?
@mohammad19991 Xcode only crashed for me when I had code coverage on.
@mohammad19991 script is for 6.1.0 version. 6.2.0 shouldn't need script but Xcode having problems...
I closed #758 but is it a new issue ? I can compile and run using SPM and execute unit tests. When I attempt to get code coverage then Xcode just crashes.
Currently can work around getting code coverage by AppCode, if anyone has similar issue