What's new in SwiftUI

RSS for tag

Discuss the WWDC21 session What's new in SwiftUI.

Posts under wwdc21-10018 tag

32 Posts

Post

Replies

Boosts

Views

Activity

Xcode 13, automatically refresh canvas does not work
[Required] Xcode 13 pod installed : 'QImageDownloader' 'QImageDownloader/Rx' 'RealmSwift' 'SwiftyRSA' 'BDGhostover' 'Charts' 'ComScore' 'Gifu' 'GoogleAnalytics' 'Google-Mobile-Ads-SDK',  'GoogleMobileAdsMediation 'Firebase' 'FirebaseMessaging' 'Firebase/Analytics' 'Firebase/Crashlytics' 'Firebase/DynamicLinks' 'Firebase/RemoteConfig' 'ImageViewer.swift' 'lottie-ios' 'OguryAds', '2.5.0' 'OguryChoiceManager', '3. 'RealmSwift' 'RxAnimated' 'RxAppState' 'RxCocoa' 'RxRealm' 'RxSwift', '~> 5' 'RxDataSources' 'SwiftyStoreKit' 'XCoordinator' 'XCoordinator/RxSwift' When I try to use swiftUI file the preview does not work at all. I need to uncheck the automatically refresh canvas in the editor. previews.txt
1
0
1.7k
Dec ’21
How to set the context menu for the header and each row of the Table component ?
I want to use the Table component to achieve the following functions Right click the column header to pop up context menu Right click each row to pop up context menu I found that TableColumn and TableRow objects are not of type view. Setting contextMenu is not supported. I can set the ContextMenu on the cell in the following ways, but it only works inside the cell, and clicking on the blank part does not take effect. TableColumn("Given Name", value: \.givenName) { person in Text(person.givenName) .contextMenu(menuItems: { Button { } label: { Text("New Order") } }) } How to set independent context menus on rows and column headers?
0
0
501
Nov ’21
How to show SF-symbols icons in SwiftUI TabView in macOS Monterey Version 12.0
I try to use TabView with tabItems that include SF-Symbols 3- Icons. To get started, I created a simple SwiftUI from the Apple SwiftUI example. I tried several variations : symbols with fill and without fill. tabItems with Stack, and without, with Label or Text and Image  ` TabView {             Text("The First Tab")                 .tabItem {                     VStack {                         Image(systemName: "1.square.fill")                         Text("First")                     }                 }             Text("The First Tab - 2")                 .tabItem {                     VStack {                         Image(systemName: "1.square")                         Text("First - 2")                     }                 }             Text("Another Tab")                 .tabItem {                     Label("second -2", systemImage: "2.square.fill")                 }             Text("Another Tab - 2")                 .tabItem {                     Label("second", systemImage: "2.square")                 }             Text("The Last Tab")                 .tabItem {                         Image(systemName: "3.square")                         Text("Third")                 }             Text("The Last Tab - 2")                 .tabItem {                         Image(systemName: "3.square.fill")                         Text("Third -2")                 }         }` The same code works when used in a preferences SwiftUI View. Is there any further prerequisite to display Icons on tabbars?
0
0
1.2k
Nov ’21
Picker under the search bar
Dear all, I want to add a Picker view under the search bar similarly as seen on the Files app: I would be happy with one of the two options - 1) to have a picker view to be visible under the search bar all the time (ie. even when the search bar is not activated), 2) to have the picker view to be visible when search bar is active. I tried to implement this by using the toolbar modifier but without luck. NavigationView {     List {         ...     }     .searchable(text: $searchText)     .toolbar {         ToolbarItem {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }     } } I have also tried the workaround by adding the Picker view within the List/Form but in this case the Picker view disappears when the user scrolls the list down.     List {         Section {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }         ...     }     .searchable(text: $searchText) } One last thing I tried was to put the picker view within the search bar’s suggestions parameter. This however, obscures the search results under the suggestions view.     List {         ...     }     .searchable(text: $searchText), suggestions: Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented) }) } Any ideas?
0
0
1.9k
Oct ’21
How to give default value to TableColumn in Table
I have this sample code: struct Item: Identifiable { var id = UUID() var name: String? } struct ItemTable: View { let items: [Item] var body: some View { Table(items) { TableColumn("Name", value: \.name) } } } I get the following error: Key path value type 'String?' cannot be converted to contextual type 'String' I can solve using \.name!, but I'd like to give a default value instead (something like \.name ?? "default"). How can I achieve this?
3
0
1.7k
Oct ’21
How to add a search bar to a list?
Hi guys, I try to use .searchable to add search bar to a list, see my code as below, but it doesn't work. How can I make it work? Somebody, please help me!!! import SwiftUI @available(iOS 15.0, *) struct ContentView: View {       var body: some View {     NavigationView {       TabView{         VStack{           List{             Text("aaa")             Text("bbb")             Text("ccc")           }           .searchable(text: .constant(""))         }         .tabItem({           Text("tab1")                     })         VStack{           Text("tab2")         }         .tabItem({           Text("tab2")                     })                 }             }         } } @available(iOS 15.0, *) struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
1
0
1.7k
Oct ’21
Xcode 13, automatically refresh canvas does not work
[Required] Xcode 13 pod installed : 'QImageDownloader' 'QImageDownloader/Rx' 'RealmSwift' 'SwiftyRSA' 'BDGhostover' 'Charts' 'ComScore' 'Gifu' 'GoogleAnalytics' 'Google-Mobile-Ads-SDK',  'GoogleMobileAdsMediation 'Firebase' 'FirebaseMessaging' 'Firebase/Analytics' 'Firebase/Crashlytics' 'Firebase/DynamicLinks' 'Firebase/RemoteConfig' 'ImageViewer.swift' 'lottie-ios' 'OguryAds', '2.5.0' 'OguryChoiceManager', '3. 'RealmSwift' 'RxAnimated' 'RxAppState' 'RxCocoa' 'RxRealm' 'RxSwift', '~> 5' 'RxDataSources' 'SwiftyStoreKit' 'XCoordinator' 'XCoordinator/RxSwift' When I try to use swiftUI file the preview does not work at all. I need to uncheck the automatically refresh canvas in the editor. previews.txt
Replies
1
Boosts
0
Views
1.7k
Activity
Dec ’21
How to use TableColumnBuilder and TableRowBuilder in SwiftUI 3.0 ?
Are there any relevant code examples to show how to use TableColumnBuilder and TableRowBuilder ?Thank you.
Replies
0
Boosts
0
Views
576
Activity
Nov ’21
How to drag the table header to reorder the columns?
Using NSTableView in Cocoa framework, it is easy to implement drag and drop sorting of table headers (not row sorting). But I didn't find out how to use the Table component in SwiftUI.
Replies
0
Boosts
0
Views
779
Activity
Nov ’21
How to set the context menu for the header and each row of the Table component ?
I want to use the Table component to achieve the following functions Right click the column header to pop up context menu Right click each row to pop up context menu I found that TableColumn and TableRow objects are not of type view. Setting contextMenu is not supported. I can set the ContextMenu on the cell in the following ways, but it only works inside the cell, and clicking on the blank part does not take effect. TableColumn("Given Name", value: \.givenName) { person in Text(person.givenName) .contextMenu(menuItems: { Button { } label: { Text("New Order") } }) } How to set independent context menus on rows and column headers?
Replies
0
Boosts
0
Views
501
Activity
Nov ’21
How does V/HStack update on Avatar Picker App on macOS?
Hello. How does V/HStack update on Avatar Picker App (The Contacts App) on macOS so smoothly? Can you share some source code, please?
Replies
0
Boosts
0
Views
844
Activity
Nov ’21
How to show SF-symbols icons in SwiftUI TabView in macOS Monterey Version 12.0
I try to use TabView with tabItems that include SF-Symbols 3- Icons. To get started, I created a simple SwiftUI from the Apple SwiftUI example. I tried several variations : symbols with fill and without fill. tabItems with Stack, and without, with Label or Text and Image  ` TabView {             Text("The First Tab")                 .tabItem {                     VStack {                         Image(systemName: "1.square.fill")                         Text("First")                     }                 }             Text("The First Tab - 2")                 .tabItem {                     VStack {                         Image(systemName: "1.square")                         Text("First - 2")                     }                 }             Text("Another Tab")                 .tabItem {                     Label("second -2", systemImage: "2.square.fill")                 }             Text("Another Tab - 2")                 .tabItem {                     Label("second", systemImage: "2.square")                 }             Text("The Last Tab")                 .tabItem {                         Image(systemName: "3.square")                         Text("Third")                 }             Text("The Last Tab - 2")                 .tabItem {                         Image(systemName: "3.square.fill")                         Text("Third -2")                 }         }` The same code works when used in a preferences SwiftUI View. Is there any further prerequisite to display Icons on tabbars?
Replies
0
Boosts
0
Views
1.2k
Activity
Nov ’21
Picker under the search bar
Dear all, I want to add a Picker view under the search bar similarly as seen on the Files app: I would be happy with one of the two options - 1) to have a picker view to be visible under the search bar all the time (ie. even when the search bar is not activated), 2) to have the picker view to be visible when search bar is active. I tried to implement this by using the toolbar modifier but without luck. NavigationView {     List {         ...     }     .searchable(text: $searchText)     .toolbar {         ToolbarItem {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }     } } I have also tried the workaround by adding the Picker view within the List/Form but in this case the Picker view disappears when the user scrolls the list down.     List {         Section {             Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented)         }         ...     }     .searchable(text: $searchText) } One last thing I tried was to put the picker view within the search bar’s suggestions parameter. This however, obscures the search results under the suggestions view.     List {         ...     }     .searchable(text: $searchText), suggestions: Picker(selection: $selectedScope) {                 ...             } label: {                 ...             }             .pickerStyle(.segmented) }) } Any ideas?
Replies
0
Boosts
0
Views
1.9k
Activity
Oct ’21
How to give default value to TableColumn in Table
I have this sample code: struct Item: Identifiable { var id = UUID() var name: String? } struct ItemTable: View { let items: [Item] var body: some View { Table(items) { TableColumn("Name", value: \.name) } } } I get the following error: Key path value type 'String?' cannot be converted to contextual type 'String' I can solve using \.name!, but I'd like to give a default value instead (something like \.name ?? "default"). How can I achieve this?
Replies
3
Boosts
0
Views
1.7k
Activity
Oct ’21
textSelection(_:) too basic
This newly added feature, is a nice step in the right direction. Wondering if anyone has any idea how to actually allow the user to "select" the text as opposed to selecting all text and offering Copy/Share?
Replies
1
Boosts
0
Views
676
Activity
Oct ’21
SwiftUI books for beginners
just wondering what recommendations people have for books on swiftui for a beginner please?
Replies
1
Boosts
0
Views
654
Activity
Oct ’21
How to add a search bar to a list?
Hi guys, I try to use .searchable to add search bar to a list, see my code as below, but it doesn't work. How can I make it work? Somebody, please help me!!! import SwiftUI @available(iOS 15.0, *) struct ContentView: View {       var body: some View {     NavigationView {       TabView{         VStack{           List{             Text("aaa")             Text("bbb")             Text("ccc")           }           .searchable(text: .constant(""))         }         .tabItem({           Text("tab1")                     })         VStack{           Text("tab2")         }         .tabItem({           Text("tab2")                     })                 }             }         } } @available(iOS 15.0, *) struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
Replies
1
Boosts
0
Views
1.7k
Activity
Oct ’21
Cannot find ‘inputImage’ in scope
Hi everyone, I’m currently making an broadcast app for iPhone / iPad and mac, for this app I need an UIImagePickerController. But in my code get the following error: Cannot find ‘inputImage’ in scope. Can anyone help me? Thanks a lot, Robby
Replies
2
Boosts
0
Views
694
Activity
Oct ’21