Posts

Post not yet marked as solved
1 Replies
370 Views
I'm converting a document based app that reads font files to use the new SwiftUI App protocol. What do I need to do to be able to open font files (.ttf, .otf, .ttc) in the app?
Posted
by emader.
Last updated
.
Post not yet marked as solved
0 Replies
840 Views
I'm converting a file viewer app to use SwiftUI. It uses an NSOutlineView to show the objects in the file and their component parts. DisclosureGroup seems like the thing to use. I have a List of DisclosureGroups, one for each of the top-level objects. The disclosure shows the component parts. This does not behave correctly. I've attached a little sample program that shows what I'm trying to do. I have built and run this little app on both macOS and iOS. It behaves differently and incorrectly on both platforms. I tried making the top-level view a VStack; that behaves better, but still doesn't do what I expect. DisclosureGroup_TestApp.swift - https://developer.apple.com/forums/content/attachment/8084981b-5d9d-4031-b5bb-62fddd655468 ContentView.swift - https://developer.apple.com/forums/content/attachment/c9a3a853-61c6-46af-99e2-f4a224297b8f
Posted
by emader.
Last updated
.
Post marked as Apple Recommended
3.3k Views
I've got a MacOS app I'm converting to use SwiftUI. The UI uses NSOutlineView. Is there a SwiftUI equivalent for this?
Posted
by emader.
Last updated
.
Post not yet marked as solved
2 Replies
596 Views
The main ContentView of my app is an HStack that contains a List of Objects, a list of the Parts of the selected objects, and the details of the selected part:Here's the ContentView code:import SwiftUI struct ContentView: View { var someObjects: [SomeObject] @State var selectedObject: SomeObject? @State var selectedPart: SomeObjectPart? var body: some View { HStack { SomeObjectView(someObjects: someObjects, selectedObject: $selectedObject).frame(width: CGFloat(exactly: 200)) SomeObjectPartView(selectedObject: $selectedObject, selectedPart: $selectedPart).frame(width: CGFloat(exactly: 200)) DetailsView(theDetails: selectedPart?.details ?? "").frame(width: CGFloat(exactly: 200)) } } }I want to set selectedPart to nil when selectedObject changes, but I can't figure out how to do that. I tried to use didSet on selected object, but it doesn't seem to get called. I also tried setting it in SomeObjectView, but that generates a runtime warning.
Posted
by emader.
Last updated
.
Post not yet marked as solved
3 Replies
2.8k Views
I've got a SwiftUI application on MacOS with a view that is a List. When the user selects an element in the list, I want the contents of another view to change based on what's selected in the List. (Like in the Mac version of the Landmarks app in the SwiftUI On All Devices talk at WWDC.)Some List initializers have a selection: parameter, but I can't find any documentation on how it works. I've been through all of the SwiftUI tutorials, but they're all for iOS, and don't seem to address this topic = they use NavigationView and NavigationLink, which don't seem applicable on MacOS.Can someone point me at some documentation for how the selection: parameter to List initializers is supposed to work? Can anyone tell me where to find the source for the Landmarks app used in the SwiftUI On All Devices talk? (Or really, anything else I can look at to figure out how to make this work?)
Posted
by emader.
Last updated
.
Post not yet marked as solved
9 Replies
11k Views
<body><p>I've got a MacOS app and I want to be able to select a particular item in a List. Here's an outline of what I'm trying to do:import SwiftUIstruct SomeObject : Identifiable { let id = UUID() let name: String // lots of other stuff}struct ContentView: View { var someObjects: [SomeObject] @Binding var selectedObject: SomeObject var body: some View { List(someObjects, selection: $selectedObject) { someObject in Text(someObject.name) } } init(_ someObjects: [SomeObject]) { self.someObjects = someObjects }}I get the error "Type of expression is ambiguous without more context" on the Text initializer, with the "n" in someObject.name underlined in red.What does this error mean? If I remove the selection: from the List initializer and take out the @Binding line, it compiles fine.
Posted
by emader.
Last updated
.
Post not yet marked as solved
2 Replies
1.2k Views
A bit of background first:I have a document based app that's a file viewer. Each file contains a bunch of tables. Each document window is a horizontal NSStackView. The left hand view shows a list of tables in the file and the right hand view is an NSTabView with two tabs. One to show the unformatted version of the table (i.e. a hex dump) and the other to show a formatted view. Currently the formatted view is a scrollable NSTableView with a single table cell.And my (probably stupid) questions:I want to use a different view for each table type, but I couldn't figure out a way to do that with AppKit. When I learned about SwiftUI, I though it would be easy to create a view that changed based on the table type, and I could put this view into an NSHostingView. I have two questions:1) I thought there'd be a way to create an NSHostingView in the storyboard, just like there is for an NSHostingViewController, but I don't see any way to to that. Have I missed somthing? Is this an as yet unimplemented feature, or is there another way to do it.2) I tried to make a SwiftUIView that contains a different view depending on the type of the selected table, but I can't figure out how to do this. Here's what I tried:import SwiftUI@available(OSX 10.15.0, *)struct FormattedView: View { var table: Table var body: some View { formattedView(table.type) } func formattedView(_ tableType: TableType) -> some View { List { if tableType == TableType.oneType { OneTypeTableFormattedView(table) } else if tableType == TableType.anotherType { AnotherTypeTableFormattedView(table) } else { Text("No formatted view for \(tableType) table") } } }}The formattedView function doesn't compile unless I embed the body in a List. It also dosen't compile if I use a switch statement instead of a if-else chain. I guess this means I'm not on the right track here. Is there a better way to do this?
Posted
by emader.
Last updated
.