Post

Replies

Boosts

Views

Activity

Reply to Xcode 27 No iOS 27 Simulators
dazboj's solution isn't working for me. id showed that my user was in daemon, along with bunches of other groups. I removed my user from it with the command shown and rebooted. On reboot, Xcode showed all the simulators I expected to see, but as soon as I selected one for iPad, it defaulted back to Any iOS Device, and then none of the simulators were in the popup any more. It's really aggrevating when Apple breaks stuff with updates, but then leaves broken things broken for years (hello, Music.app on macOS).
2d
Reply to SwiftData Model object added to multiple parent objects moves ownership to only last parent
I figured it out. I'd either misunderstood what I'd read somewhere, or it was just wrong, when it said that SwiftData would figure out all the relationships when the models were so simple. So I didn't think I needed the Genre to also contain an array of all the Discs that use it. Turns out it still needs to be specified, just like with CoreData.
2w
Reply to Binding Picker to enum value in SwiftData struct
Nevermind. The confusion of how SwiftData migrates the store when new fields are added made the data bad. After throwing out the store, I can now use the picker in a simple way: Picker("Media", selection:$item.media) { ForEach(Media.allCases, id:\.self) { media in Text(media.rawValue); } } .labelsHidden() Not sure if it needs that id in the ForEach.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w
Reply to How to send a message from menu item in SwiftUI App to ContentView
I found that I can send a custom notification from the function that receives the menu item action to my ContentView, and that works, getting around the whole "this is not the view that you're searching for" junk. Pretty sure this will be the last SwiftUI app I'll ever write. I tried one before that should've been simple, but again I hit a wall of complexity and things that just aren't possible and went back to the glory that is Cocoa for that. At least things show up in the debugger there.
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
Well, I need more than a refresher course, since I've just been trying to understand how each piece of SwiftUI works when I come to it. I never been so stymied and angry at a language in all my 48 years of programming. Here's the relevant code. Comments say what works and what doesn't: @main struct SpeakotronikApp: App { @State public var contentView = ContentView(); @State var showFileImporter:Bool = false; var body:some Scene { WindowGroup { self.contentView .environment(langModel) } .commands { CommandGroup(after:.newItem) { Button("Import…") { self.showFileImporter = true; } .fileImporter(isPresented:$showFileImporter, allowedContentTypes:[.text], allowsMultipleSelection:false) { result in switch result { case .success(let urls): for url in urls { // Tell the content view to read the file and add new terms that will be translated: self.contentView.importTerms(url:url); } case .failure(let error): print("Error selecting file: \(error.localizedDescription)"); } } } } } } struct ContentView: View { @Environment(LangViewModel.self) private var langModel; @State private var selectedLang:Locale.Language = ...a language...; // This variable causes .translationTask to run when called from code contained in ContentView (.onChange), which works: @State var sequenceTranslationConfig:TranslationSession.Configuration?; var body: some View { VStack { ...buttons and stuff... } .onChange(of:selectedLang) { // Trigger the sequence translations to run: sequenceTranslationConfig = .init(source:Locale.current.language, target:selectedLang, preferredStrategy:.highFidelity); } .translationTask(sequenceTranslationConfig) { session in await langModel.translateSequence(using:session, terms:self.terms); } } public func importTerms(url:URL) { // Gain temporary permission to read security-scoped sandbox files guard url.startAccessingSecurityScopedResource() else { return } // Defer release of the system permission defer { url.stopAccessingSecurityScopedResource() } do { ...read file and do stuff with it... // Trigger my sequence translations to happen, which does NOT work: sequenceTranslationConfig = .init(source:Locale.current.language, target:selectedLang, preferredStrategy:.highFidelity); } catch { print("Error reading file: \(error.localizedDescription)") } } }
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
OK, so now the fileImporter is being run from the command in the app. It calls a function on the ContentView to import files. That function needs to do some other things to itself, so it sets the value of a @State TranslationSession.Configuration in the ContentView to a new instance, which is supposed to kick off a translationTask. Nothing happens, I assume because it's not being called from within a View hierarchy, but from the app. Why is it so difficult to make things work in SwiftUI?
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
I tried moving showFileImporter to the app and sharing it in the environment, but Swift hates that. struct SpeakotronikApp: App { @State var showFileImporter:Bool = false; var body:some Scene { WindowGroup { ContentView() .environment(showFileImporter) } } Instance method 'environment' requires that 'Bool' be a class type Instance method 'environment' requires that 'Bool' conform to 'Observable'
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
You could use environment variables for showFileImporter and remove the contentView state var to solve the issue. I'd thought about that, but it seems like bad practice to keep a variable in the app when only the ContentView actually uses it. But then there are many things about Swift that are illogical. Note: in Swift, you don't need to end statements with semicolon. I know, yet I do, because I always have in all other languages I've ever used, and always will. They add important visual endings to each line of code. I missed one in my editing of the example in my original post.
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’26
Reply to Xcode 27 No iOS 27 Simulators
dazboj's solution isn't working for me. id showed that my user was in daemon, along with bunches of other groups. I removed my user from it with the command shown and rebooted. On reboot, Xcode showed all the simulators I expected to see, but as soon as I selected one for iPad, it defaulted back to Any iOS Device, and then none of the simulators were in the popup any more. It's really aggrevating when Apple breaks stuff with updates, but then leaves broken things broken for years (hello, Music.app on macOS).
Replies
Boosts
Views
Activity
2d
Reply to SwiftData Model object added to multiple parent objects moves ownership to only last parent
I figured it out. I'd either misunderstood what I'd read somewhere, or it was just wrong, when it said that SwiftData would figure out all the relationships when the models were so simple. So I didn't think I needed the Genre to also contain an array of all the Discs that use it. Turns out it still needs to be specified, just like with CoreData.
Replies
Boosts
Views
Activity
2w
Reply to Binding Picker to enum value in SwiftData struct
Nevermind. The confusion of how SwiftData migrates the store when new fields are added made the data bad. After throwing out the store, I can now use the picker in a simple way: Picker("Media", selection:$item.media) { ForEach(Media.allCases, id:\.self) { media in Text(media.rawValue); } } .labelsHidden() Not sure if it needs that id in the ForEach.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
2w
Reply to SwiftUI design options needed
I was using a NavigationSplitView, but the huge mess of different ways it can be used was throwing a wrench into the works. The linked article really helped and showed different things that actually worked. Thanks!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
3w
Reply to How to send a message from menu item in SwiftUI App to ContentView
I found that I can send a custom notification from the function that receives the menu item action to my ContentView, and that works, getting around the whole "this is not the view that you're searching for" junk. Pretty sure this will be the last SwiftUI app I'll ever write. I tried one before that should've been simple, but again I hit a wall of complexity and things that just aren't possible and went back to the glory that is Cocoa for that. At least things show up in the debugger there.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
Well, I need more than a refresher course, since I've just been trying to understand how each piece of SwiftUI works when I come to it. I never been so stymied and angry at a language in all my 48 years of programming. Here's the relevant code. Comments say what works and what doesn't: @main struct SpeakotronikApp: App { @State public var contentView = ContentView(); @State var showFileImporter:Bool = false; var body:some Scene { WindowGroup { self.contentView .environment(langModel) } .commands { CommandGroup(after:.newItem) { Button("Import…") { self.showFileImporter = true; } .fileImporter(isPresented:$showFileImporter, allowedContentTypes:[.text], allowsMultipleSelection:false) { result in switch result { case .success(let urls): for url in urls { // Tell the content view to read the file and add new terms that will be translated: self.contentView.importTerms(url:url); } case .failure(let error): print("Error selecting file: \(error.localizedDescription)"); } } } } } } struct ContentView: View { @Environment(LangViewModel.self) private var langModel; @State private var selectedLang:Locale.Language = ...a language...; // This variable causes .translationTask to run when called from code contained in ContentView (.onChange), which works: @State var sequenceTranslationConfig:TranslationSession.Configuration?; var body: some View { VStack { ...buttons and stuff... } .onChange(of:selectedLang) { // Trigger the sequence translations to run: sequenceTranslationConfig = .init(source:Locale.current.language, target:selectedLang, preferredStrategy:.highFidelity); } .translationTask(sequenceTranslationConfig) { session in await langModel.translateSequence(using:session, terms:self.terms); } } public func importTerms(url:URL) { // Gain temporary permission to read security-scoped sandbox files guard url.startAccessingSecurityScopedResource() else { return } // Defer release of the system permission defer { url.stopAccessingSecurityScopedResource() } do { ...read file and do stuff with it... // Trigger my sequence translations to happen, which does NOT work: sequenceTranslationConfig = .init(source:Locale.current.language, target:selectedLang, preferredStrategy:.highFidelity); } catch { print("Error reading file: \(error.localizedDescription)") } } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
OK, so now the fileImporter is being run from the command in the app. It calls a function on the ContentView to import files. That function needs to do some other things to itself, so it sets the value of a @State TranslationSession.Configuration in the ContentView to a new instance, which is supposed to kick off a translationTask. Nothing happens, I assume because it's not being called from within a View hierarchy, but from the app. Why is it so difficult to make things work in SwiftUI?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
I tried moving showFileImporter to the app and sharing it in the environment, but Swift hates that. struct SpeakotronikApp: App { @State var showFileImporter:Bool = false; var body:some Scene { WindowGroup { ContentView() .environment(showFileImporter) } } Instance method 'environment' requires that 'Bool' be a class type Instance method 'environment' requires that 'Bool' conform to 'Observable'
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’26
Reply to How to send a message from menu item in SwiftUI App to ContentView
You could use environment variables for showFileImporter and remove the contentView state var to solve the issue. I'd thought about that, but it seems like bad practice to keep a variable in the app when only the ContentView actually uses it. But then there are many things about Swift that are illogical. Note: in Swift, you don't need to end statements with semicolon. I know, yet I do, because I always have in all other languages I've ever used, and always will. They add important visual endings to each line of code. I missed one in my editing of the example in my original post.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’26