Post

Replies

Boosts

Views

Activity

Reply to Force a locale from string catalog
Many thanks Apple Engineer, func localizedString( is exactly what I needed and the fog is clearing :) Reminder to myself: func localizedString(_ resource: LocalizedStringResource, _ myLocale: String) -> String { var locale: Locale { Locale(identifier: myLocale) } var resource = resource resource.locale = locale return String(localized: resource) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to Force a locale from string catalog
LocalizedStringResource didn't seem to work. The .environment modifier may work on Views but not on the content of the view ( strings in the view used to build the shared content) However, the localizedString method suggested by AI did work despite looking messy. A shame there's not a simpler solution. @State var isOtherLanguage = false var body: some View { var myLocale: String { isOtherLanguage ? "de" : "en" } VStack { Toggle("Switch language", isOn: $isOtherLanguage).frame(maxWidth: 200) HStack { Text("❌\(myLocale): ") Text( LocalizedStringResource( "Hello world!", table: "Localizable", locale: Locale(identifier: myLocale) ) ) } HStack { Text("❌\(myLocale): ") Text( String( localized: "Hello world!", locale: (Locale(identifier: myLocale)), comment: "To share" ) ) .environment(\.locale, Locale(identifier: myLocale)) } HStack { Text("❌\(myLocale): ") Text(localizedString) } HStack { Text("✅\(myLocale): ") Text("Hello world!") .environment(\.locale, Locale(identifier: myLocale)) } HStack { Text("✅\(myLocale): ") Text(localizedString("Hello world!", locale: myLocale)) } } } func localizedString(_ key: String.LocalizationValue, locale: String) -> String { guard let path = Bundle.main.path(forResource: locale, ofType: "lproj"), let bundle = Bundle(path: path) else { return String(localized: key) } return String(localized: key, bundle: bundle) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’25
Reply to How to create a second target for an app with a linked App Clip?
Here's how to fix it... In the target for the Test Flight App in the general tab you'll find a framework, library, clips section and this contains the reference to the clip ( a relic of copying the original production target.) This must be deleted. However, you cannot delete it here (if you try, you'll get warning popups etc but the deletion fails. ) Instead, navigate to the Build Phases tab and scroll down to the Embed App Clips section and here you can delete it. Warning: Make sure you do this in the test flight target not the production target.
Feb ’25
Reply to Run identical UI/Unit tests on different build targets
I discovered this nugget of Apple Documentation. It visualises how the scheme is the link specifying which build target is used by the test target. Unfortunately this doesn't seem to be the case. The host application field in the test target (general tab) appears to be the main determinator. So my assumptions above seem to be correct, and you can be easily be misled into assuming one build target is used whereas in fact another target is used. Tip: Include a screenshot of the about page of your app/clip/widget to avoid being misled.
Nov ’24
Reply to NSCocoaErrorDomain 513
Solved. I'm not sure where or how Sandbox is selected as a capability. I'd much rather it wasn't. But my problem was that User Selected File (see screenshot above) was specified as read/write in the release tab, but none in the debug tab.
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’24
Reply to NSCocoaErrorDomain 513
I'm also getting a 513 error no matter what I code. I even tried using chatGTP and Harmony and Copilot generated code. All to no avail. Here's the copilot code (as it seemed better to me) func copilotCreateTheNewDirectory(in downloadsURL: URL) { guard downloadsURL.startAccessingSecurityScopedResource() else { let errorMessage = "Failed to access the selected location" showError = true return } defer { downloadsURL.stopAccessingSecurityScopedResource() } let newDir = "myShinyNewDir" let fileManager = FileManager.default let newDirectoryURL = downloadsURL.appendingPathComponent(newDir) do { try fileManager.createDirectory( at: newDirectoryURL, withIntermediateDirectories: false, attributes: nil ) } catch { let errorMessage = "Failed to create directory: \(error.localizedDescription)" showError = true } } } I tried using Swift5 instead of Swift6 and that failed, too. I tried in Documents and Downloads locations - all failed. Here are my App Sandbox settings: Xcode: Version 16.0 (16A242d) MacOS: Sequoa 15.0.1
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’24