What's new in SwiftUI

RSS for tag

Discuss the WWDC22 Session What's new in SwiftUI

Posts under wwdc2022-10052 tag

26 Posts
Sort by:
Post not yet marked as solved
2 Replies
966 Views
I was playing around with TableColumn api in MacOS Ventura I have the following data model. actor HousingData: Identifiable {     let id: Int     let rank: Int     let region: String     let regionType: RegionType     let state: String } However when it try to do TableColumn("foo", value: \.rank) I get Key path value type 'Int' cannot be converted to contextual type 'String' if I try TableColumn("Rank", value: \.rank) { rank in Text("\(rank)") } I get Referencing initializer 'init(_:value:content:)' on 'TableColumn' requires the types 'Never' and 'KeyPathComparator<HousingData>' be equivalent If i use a string value all works well.
Posted Last updated
.
Post not yet marked as solved
1 Replies
281 Views
now matter what view i create tor token it takes only first Text/Label element for display. Is it possible to customize it so it would look something like in Mail app ?
Posted
by LaimonaS.
Last updated
.
Post marked as solved
2 Replies
1k Views
I would like to include the bottom sheet from the iPhone "find my" and "maps" app in my app. During my research I came across the new modifier .presentationDetents for sheets. The only problem here is that you can no longer interact with the main screen when the sheet is active. In my app, however, I would like the sheet to be active all the time like in the iPhone apps mentioned and that you can still interact with the main screen like in the iPhone apps with the map. I would be very happy about help. Greetings
Posted Last updated
.
Post not yet marked as solved
2 Replies
649 Views
I’m unable to use the .searchScopes modifier to add a segmented Picker to my search bar as of developer beta 6. It will not display whether I’m using a NavigationStack, NavigationSplitView, or NavigationView. Has anyone had any luck using this modifier? This simple code will demonstrate the problem. struct ContentView: View {     @State var searchText: String = ""     @State var searchScope: String = "Scope 1"         let data = Array(0..<20)     var body: some View {         NavigationStack {             List {                 ForEach(data, id:\.self) { item in                    Text("\(item)")                 }             }             .searchable(text: $searchText)             .searchScopes($searchScope, scopes: {                     Text("Scope 1")                     Text("Scope 2")             })         }     } } I've submitted this as FB11298015
Posted Last updated
.
Post not yet marked as solved
1 Replies
710 Views
Menu {      ShareLink(...) ShareLink(...)      ShareLink(...) } label: {   Label("Share", systemImage: "square.and.arrow.up") } Here, I have different share options to choose from, and if I tap one of these share link to share sheet doesn't pop up. Is there any workaround to this issue?
Posted Last updated
.
Post not yet marked as solved
8 Replies
4.3k Views
In SwiftUI 3 we used the following code snippet to set the background color of a list. struct ContentView: View {     var body: some View {         List {             Text("Hello World!")         }         .onAppear { // Placed here for sample purposes, normally set globally             UITableView.appearance().backgroundColor = .clear         }         .listStyle(.insetGrouped)         .background(Color.red)     } } This is not working anymore in SwiftUI 4 (FB10225556) as the List is not based on UITableView anymore. Any workaround ideas?
Posted
by saibot.
Last updated
.
Post not yet marked as solved
3 Replies
845 Views
The new NavigationSplitView is very handy. I want to use it for a settings screen, but I need a way to navigate in and out of it. Previously I just navigated in and out of my settings using a NavigationView. But if I change this to a NavigationStack, and then navigate forward into a NavigationSplitView from it, it almost works fine, but some weirdness happens: on iPhone there are two competing back arrows (i.e "<") and on an iPad there is weird spacing at the top of the screen. Should I be able to navigate from a NavigationStack into a NavigationSplit View? If so, are these known issues? If not, is there a recommended UI for navigating in and out of a NavigationSplitView from the rest of my iPhone/iPad app? thanks!
Posted
by breville.
Last updated
.
Post not yet marked as solved
0 Replies
554 Views
If you configure a Window and a MenuBarExtra in your app, try this: Open your app and press Command+H to hide it. Place an iPad or another Mac and connect two devices via Universal Control, and click on the other device to make your mac's menu bar inactive. Move your cursor back to your Mac(first device), and click on the whitespace of the Menu Bar. Your App is terminated unexpectedly. This behavior will only appear on those apps using Window, so to solve this issue, we may need to switch Window to WindowGroup which is not what we want. I reappear this issue on Apple's ScreenCaptureKit Sample Code. This is a SwiftUI Scene BUG, please fix this. @main struct CaptureSampleApp: App { var body: some Scene { Window("ID", id: "ID") { ContentView() .frame(minWidth: 960, minHeight: 724) .background(.black) } MenuBarExtra( "App Menu Bar Extra", systemImage: "star" ) { Text("Hello") } } } Filed a feedback: FB11447959.
Posted Last updated
.
Post not yet marked as solved
0 Replies
522 Views
When integrating the new ShareLink into my project, I noticed two unexpected things. First, when I pass a SharePreview to my sharelink with just a title and no image as a pararameter, my AppIcon suddenly loads in the preview. Is that normal? Just with that code: ShareLink(item: appStoreUrl, message: Text(["", ""].randomElement()!), preview: SharePreview("ProTimer")) { Label { Text("ProTimer weiterempfehlen") .tint(.primary) } icon: { Image(systemName: "square.and.arrow.up") } } My second question is, why can't I pass a subtitle in the SharePreview, only the title in bold?
Posted Last updated
.
Post marked as solved
2 Replies
651 Views
So I have a navigationStack which has a NavigationLink that navigates to the next view. That view then has its own NavigationLink that navigate to a 3rd view. if the user clicks on the back button on the 3rd view (View3) to return to the previous view (View 2), it goes right back to the starting view (View 1). an one else have this issue or know how to fix? ios16b1 example below: View 1: NavigationStack {                 View2()                     .navigationTitle("View 2")             } View 2: List {        VStack (alignment: .leading) {                     NavigationLink("View 3", destination: {                         View3()                     }) } }
Posted
by ngb.
Last updated
.
Post not yet marked as solved
1 Replies
778 Views
Is it possible to use create a "nonmodal sheet" as described in the Human Interface Guidelines and as seen in apps like Maps using SwiftUI's .sheet and the new .presentationDetents modifier in iOS 16. By default, the content behind the sheet is not interactive. Is there a built in modifier or modality style that can be applied to the sheet to allow for interactive content behind the sheet?
Posted Last updated
.
Post marked as solved
4 Replies
550 Views
I have tried to copy the code from a WWDC 2022 presentation. It worked successfully once, and now I am trying to copy a different point of code later in the same presentation. It keeps giving me the code that I have already copied. Any ideas on how to get this to work would be great! Thank you, Bob
Posted
by BLawson.
Last updated
.
Post not yet marked as solved
3 Replies
1.6k Views
I can't seem to find a way to change List's background color. Modifier .background() has no effect on List background color. Putting List in a ZStack & applying .background modifier to it also has no effect I know that starting with iOS 16 List is backed by UICollectionView so old tricks with .appearance() does not work anymore. Using ZStack with .plain list style also has no effect. Intospecting view hierarchy kinda works but List resets its bg color on update List is such a fundamental component and having no ability to change its background color is very limiting
Posted Last updated
.
Post marked as solved
2 Replies
1.1k Views
Dear All, How do I share a PDFDocument using the new ShareLink of the SwiftUI? The following code does not compute: let pdf = PDFDocument(data: data) ShareLink(items: pdf.dataRepresentation()!) Thanks.
Posted
by tomas.bek.
Last updated
.
Post not yet marked as solved
0 Replies
554 Views
There seems to be no way to add dynamically add table columns to SwfitUI table. I have a column of dates that I store in an array like so. let dates = [Date] let values = [Int] I want one able enumerate over the dates to generate columns. However I can't seem to find a way to enumerate over them and generate my columns. My current data set has 250 columns and it will keep growing. I would love to do ForEach(0 ..< dates.length) { index in TableColumn("<some formatted date>") { Text("\(value)") } } But it appears that since TableColumn is not a view ForEach can't be used. Is there a supported way to build columns dynamically? This is a Mac application. Does charts support a for each type symantic too?
Posted Last updated
.
Post not yet marked as solved
0 Replies
692 Views
Dear All, Recent updates in SwiftUI allow to add scope bars just beneath the search bar. Those are limited in space, though. How does one implement a scrollable filter as is seen in the Apple’s own Developer app?
Posted
by tomas.bek.
Last updated
.
Post not yet marked as solved
2 Replies
994 Views
My question concerns a macOS SwiftUI app. I would like to have a split view with 2 horizontal panes without sidebar: content on the left and inspector on the right. The inspector should act like the inspector panel on the right side side of the Xcode's window: when the window is resized, the inspector keeps it's current width and the user can resize the inspector using the split divider. Using macOS Monterey SDK, I tried to achieve this with HSplitView but the problem is that the left/right panels are both resized when the window is resized. struct ContentView: View { var body: some View { HSplitView { Rectangle().fill(.red) Rectangle().fill(.yellow) } } } Using Ventura SDK, I just tried the new view NavigationSplitView. I'm using .constant(.doubleColumn) to hide the sidebar but the problem is the same as HSplitView, the left/right panel are both resized when the window is resized. struct ContentView: View { var body: some View { NavigationSplitView(columnVisibility: .constant(.doubleColumn)) { Text("not used") } content: { Rectangle().fill(.red) } detail: { Rectangle().fill(.yellow) } } } When using NSSplitViewController with AppKit, the holdingPriority (https://developer.apple.com/documentation/appkit/nssplitviewitem/1388887-holdingpriority?language=objc) allows to manage this case: The view with the lowest priority is the first to gain additional width if the split view grows or shrinks. Is it possible to achieve this with SwiftUI?
Posted
by benoit.
Last updated
.