Post

Replies

Boosts

Views

Activity

Reply to Programmatically create MenuBarExtra elements
MenuBarExtra vs Menu MenuBarExtra is like adding a mini app that lives on the menu bar What you are trying to achieve seems similar to what Menu does (https://developer.apple.com/documentation/swiftui/menu) Menu items could even have keyboard shortcuts. Pasted below is from Apple's documentation. Menu("Actions") { Button("Duplicate", action: duplicate) Button("Rename", action: rename) Button("Delete…", action: delete) Menu("Copy") { Button("Copy", action: copy) Button("Copy Formatted", action: copyFormatted) Button("Copy Library Path", action: copyPath) } }
Aug ’23
Reply to Programmatically create MenuBarExtra elements
Use ForEach inside MenuBarExtra as shown below: @main struct SwiftBarApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } MenuBarExtra("Title") { ForEach(appDelegate.menuItems, id:\.self) { menuItemSet in MenuBarView(menuItemSet: menuItemSet) } } } }
Aug ’23
Reply to Output print statements
Problem NavigationLink and Button both perform actions. So having both NavigationLink and Button doesn't make sense, so the action of the button is ignored. Points to note NavigationLink is used for navigation NavigationView is deprecated, so use NavigationStack instead Solution Given below is sample code using NavigationStack, use onChange(of:) to detect any changes to path. Tip You could even pass the path variable as a binding to the destination views struct ContentView: View { @State private var path = [Int]() var body: some View { NavigationStack(path: $path) { VStack { NavigationLink(value: 1) { Rectangle() .frame(width: 100, height: 100) } NavigationLink(value: 2) { Rectangle() .frame(width: 100, height: 100) } NavigationLink(value: 3) { Rectangle() .frame(width: 100, height: 100) } } .navigationDestination(for: Int.self) { value in Text("Selected box: \(value)") } } .onChange(of: path) { newPath in print("path: \(newPath)") } } }
Aug ’23
Reply to Xcode beta 5 crashes when adding a file to a project
Problem This happens consistently in the following environment: macOS: 14.0 Beta (23A5301h) Xcode: Version 15.0 beta 5 (15A5209g) Crash happens when adding a new file. Observation File gets written to disk then Xcode crashes. Subsequently after re-opening Xcode able to add a file from disk. However consisting crashes when creating a new file Works fine The same version of Xcode works fine on macOS 13.5
Aug ’23
Reply to SwiftData Query relationships not working
@Purkylin_glow @albert.tra Not sure if this is a good solution, but the following seems to work (it has downsides): List { ForEach(students.filter { $0.department?.id == department.id }) { student in Text(student.name) } } The downside is@Query would monitor changes and refresh the view even if a student is added to a totally different department. I really wish there is a better solution ...
Jun ’23
Reply to How to download macOS Sonoma installer?
@endecotp Thank you for the good suggestion and @Systems Engineer thanks for the confirmation. I was so confused if I was missing something obvious. @Systems Engineer so what is the IPSW file for (and how to use that)? I wish there was documentation about it, all I read was it is used by Apple Configurator but that is only for iOS IPSW files.
Jun ’23