Post

Replies

Boosts

Views

Activity

Reply to Two document types in SwiftUI?
It looks like the answer is no. The second DocumentGroup is necessary for opening a file of the second type, but I haven't found a way to make SwiftUI create a document of that type. Using .handlesExternalEvents doesn't seem to help, as it seems to want to open a window defined by a WindowGroup rather than a DocumentGroup. The best idea I've come up with is to create a temporary file and then push the URL for that to openURL, but that leaves the user with a file which they don't actually need, and doesn't replicate the experience of a new document.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to Selection disappearing in NSTableView inside SwiftUI
I never got an answer, but I solved my problem by redesigning the table to be expressible as a SwiftUI List, which does away with the awkward interaction with NSTableView. I got a cleaner design in some ways, but I lost a couple of things, particularly the ability to shade alternate rows to make it easier to read, and sorting by columns. Neither is a show-stopper, so I'm going with what I've come up with.
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21
Reply to How to make a list with a filter field in SwiftUI on Mac
I eventually figured out that the important thing I was missing was "id: \.self" in the List statement. I'd understood the documentation to say that wasn't necessary if the content conformed to Identifiable, but I was mistaken, and you need to specify the identifier. Your solution is interesting, and worth thinking about as I continue to work on the project.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
Reply to Selection disappearing in NSTableView inside SwiftUI
Since there's been no reply, here's most of the code for the NSViewControllerRepresentable class: Swift struct LayoutsTableView: NSViewControllerRepresentable { typealias NSViewControllerType = LayoutsTableController @Binding var layoutsList: [LayoutData]     @Binding var selectedIndex: Int func makeNSViewController(context: Context) - LayoutsTableController { let theTable = LayoutsTableController(nibName: "LayoutsTable", bundle: Bundle.main) theTable.layoutList = layoutsList         theTable.tableDelegate = context.coordinator // So that the table can set its delegate after it appears         context.coordinator.tableController = theTable return theTable }     func makeCoordinator() - Coordinator {         return Coordinator(self)     } func updateNSViewController(_ nsViewController: LayoutsTableController, context: Context) { nsViewController.layoutsTable.reloadData() }     final class Coordinator: NSObject, NSTableViewDelegate {         var parentView: LayoutsTableView         var tableController: LayoutsTableController?         init(_ parent: LayoutsTableView) {             parentView = parent         }         // MARK: Table Delegate methods         func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) - NSView? { // returns the appropriate view         }         func tableViewSelectionDidChange(_ notification: Notification) {             let selectedRow = tableController?.layoutsTable.selectedRow ?? -1             parentView.selectedIndex = selectedRow         }     } } Any clues, anyone?
Topic: UI Frameworks SubTopic: AppKit Tags:
Mar ’21