I have a weird issue I can't figure out (hope this is the correct forum for it). I've implemented an SPM package which contains DateFormatter extensions. When implementing this DateFormatter:
I have the same implementation in a SwiftUI View or ViewModel in the main app. When I compare the TimeZone between the DateFormatter created locally or in the SPM package there's a difference in TimeZone, see attached screenshot.
The top one is the locally created DateFormatter (same implementation) and the bottom one is the DateFormatter that's created in the SPM library.
When I compare the TimeZone between the DateFormatter created
locally or in the SPM package there's a difference in TimeZone, see
attached screenshot.
I’d like to clarify this. To see different behaviour you have to have different execution environments. An “[SwiftPM] package” isn’t an execution environment, it’s just a bunch o’ code. To see its behaviour, you have to run it. How are you running it?
If you load the SwiftPM code into your SwiftUI app, I’d be very surprised if it behaved differently from the code that’s built in to that app.
Since all the DateFormatters are static, when changing the TimeZone on a DateFormatter somewhere else it'll be changed everywhere since there's only one instance. I tested this in a playground and it is exactly the behaviour I have in my app. So it has nothing to do with SPM packages, it's just the method I created which breaks it.