4

According to the documentation, we should be able to set the locale on previews and the following code should work:

import SwiftUI

struct TestView: View {
    
    var timeFormatter: DateFormatter {
        let formatter = DateFormatter()
        formatter.dateStyle = .full
        formatter.timeStyle = .none
        return formatter
    }

    var body: some View {
        Text(timeFormatter.string(from: Date.now))
    }
}

struct TestView_Previews: PreviewProvider {
    static var previews: some View {
        TestView().environment(\.locale, .init(identifier: "fr_FR"))
    }
}

But it does not, and here is what I have in Xcode 14.1 (14B47b):

preview screenshot

Am I missing something? Is this a known issue?

adauguet
  • 988
  • 8
  • 18

0 Answers0