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) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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)") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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 ...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to SwiftData Query relationships not working
@Purkylin_glow The problem with using department.students is that when the + button is tapped to add new students, it doesn't show up in the student list unless you go back to the department list and come back to Student list screen. New changes to department.students are not observed
Topic: UI Frameworks SubTopic: SwiftUI Tags:
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.
Topic: App & System Services SubTopic: Core OS Tags:
Jun ’23
Reply to Downgrade macOS 14 Sonoma Beta (23A5257q)
Not sure if the following helps, but that is what I did (after accidentally upgrading to macOS Sonoma). Xcode 15 beta will work on macOS Sonoma but you can't submit updates with Xcode beta. Note: I am no expert, so do with caution. How I wiped and installed macOS Ventura: Took a backup Downloaded macOS Ventura from the App Store Created a bootable USB disk of macOS Ventura Booted with USB, wiped disk Install macOS Ventura Copied files from backup. I still don't know how to download the macOS Sonoma installer without upgrading. Any help would be appreciated.
Jun ’23
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) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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) } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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)") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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
Replies
Boosts
Views
Activity
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 ...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to SwiftData Query relationships not working
@Purkylin_glow The problem with using department.students is that when the + button is tapped to add new students, it doesn't show up in the student list unless you go back to the department list and come back to Student list screen. New changes to department.students are not observed
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jun ’23
Reply to Downgrade macOS 14 Sonoma Beta (23A5257q)
Not sure if the following helps, but that is what I did (after accidentally upgrading to macOS Sonoma). Xcode 15 beta will work on macOS Sonoma but you can't submit updates with Xcode beta. Note: I am no expert, so do with caution. How I wiped and installed macOS Ventura: Took a backup Downloaded macOS Ventura from the App Store Created a bootable USB disk of macOS Ventura Booted with USB, wiped disk Install macOS Ventura Copied files from backup. I still don't know how to download the macOS Sonoma installer without upgrading. Any help would be appreciated.
Replies
Boosts
Views
Activity
Jun ’23