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
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Aug ’25
Reply to What's the trick for copying a file to a simulator session?
I checked on a Mac mini . The share method worked there. Here’s hoping the next macOS update solves the problem for my MacBook.
Replies
Boosts
Views
Activity
Jun ’25
Reply to What's the trick for copying a file to a simulator session?
Additional information.... Even if I use safari to download the file from google drive or icloud it fails with no message at all. I suspect it's either an authorisation problem (can't determine how to authorize safari to access the simulation files) or a missing directory (i.e. simulator is trying to download to a non-existent directory).
Replies
Boosts
Views
Activity
Jun ’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.
Replies
Boosts
Views
Activity
Feb ’25
Reply to New Target for project with an App Clip
Posted in the wrong forum and I cannot figure how to move it so I’m closing this post.
Replies
Boosts
Views
Activity
Feb ’25
Reply to Guidelines for ViewThatFits to avoid run-time crashes
Apple replied today to say the problem has now been now fixed: Xcode 16.3 beta (16E5104o) https://developer.apple.com/download/ Posted Date: February 21, 2025
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Feb ’25
Reply to @Observation: Best way of handling binding after injecting a View-Model
I've researched. The diagram is a slight oversimplification. Alternative 2 (@State) is the correct answer.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’24
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.
Replies
Boosts
Views
Activity
Nov ’24
Reply to CreateML for Image recognition with a spreadsheet catalog
Here's the code: https://github.com/alanrick/CreateMLImageDistributor
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Nov ’24
Reply to NSCocoaErrorDomain 513
Same problem in Sequoa 15.1. But, when I copy the same code into another project it works. There must be some project/profile/info.plist setting that makes all the difference 🙁
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Nov ’24
Reply to CreateML for Image recognition with a spreadsheet catalog
I created this enhancement request: FB15562835 I also coded a small MacOS App to generate folders and copy images into them based on a spreadsheet. This satisfies my requirements, but of course I'd prefer this capability to be available directly in CreateML. I'll put the App's code in GitHub soon.
Replies
Boosts
Views
Activity
Oct ’24
Reply to Preview crashes consistency in Xcode 16 beta
One of my projects crashes consistently every few minutes in Xcode 16.0 so I set it to legacy preview. Keywords in case anyone else googles for the problem: AccessibilityControlsExtension Responsible Process: SimulatorTrampoline
Replies
Boosts
Views
Activity
Sep ’24