Post

Replies

Boosts

Views

Activity

Reply to How do I add MenuItem to menubar in macos using SwiftUI?
Thanks, that did help. For completeness, I wrote this small sample app that adds a new menu item to the menu and overrides the copy menu. @main struct MenuTestApp: App {   var body: some Scene {     WindowGroup {       ContentView()     }     .commands {       CommandMenu("My Top Menu") {         Button("Sub Menu Item") { print("You pressed sub menu.") }           .keyboardShortcut("S")       }       CommandGroup(replacing: .pasteboard) {         Button("Cut") { print("Cutting something...") }           .keyboardShortcut("X")         Button("Copy") { print("Copying something...") }           .keyboardShortcut("C")         Button("Paste") { print("Pasting something...") }           .keyboardShortcut("V")         Button("Paste and Match Style") { print("Pasting and Matching something...") }           .keyboardShortcut("V", modifiers: [.command, .option, .shift])         Button("Delete") { print("Deleting something...") }           .keyboardShortcut(.delete)         Button("Select All") { print("Selecting something...") }           .keyboardShortcut("A")       }     }   } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21
Reply to How to override Edit>Copy when first responder cannot copy
My app is displaying a default value as the user enters data in the TextField. It is clear that this data that is being displayed will be copied. The problem does not seem to be related to Enabled since it is set in IB. I got it to work by removing the view that had focus (in my case a TextField). When I did this, Copy was enabled and my copy function in code above was called. My problem still seems to be related to providing and telling the system that copy is available when the current first responder cannot handle it. I've tried various things like creating my own NSTextField and trying to override copy but without success. I've also created a new SwiftUI app and posted this thread - https://developer.apple.com/forums/thread/667633 since it more clearly shows my issue. ps. Sorry for the late reply. It seems my notifications are not working.
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’20
Reply to How do I get a Picker to show initial and selected value?
I found that changing my picker to use an Enum works: Picker("Pick Something: ", selection: $pickedValue) { 	ForEach(TestState.allCases) { state in 		Text(state.rawValue).tag(state) 	} } Why would this work differently from the initial code? TestState is declared: enum TestState: String, CaseIterable, Identifiable {   case one   case two   var id: String { self.rawValue } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20