Swift UI, use Picker, forEach and Section together has error

I am using ForEach() inside a Picker, but the debug gives an error.

Xcode Version 11.2 (11B52)


Below is my swift code

var radiusRangeKM = Array((stride(from: 50, to: 2010, by: 10)))

  var body: some View {
  NavigationView {
  //TODO: Form Set Up
  Form {

   Section() {
    Picker(selection: $selectedRadius, label: Text("Radius(KM)")) {
     ForEach(0 ..< radiusRangeKM.count, id: \.self) {
       Text(String(self.radiusRangeKM[$0])).tag($0)
     }
    }

   }


  }
  .navigationBarTitle(Text("Settings"))
  }
}


Below is the error from debug window


[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7f9d5e98b000; baseClass = UITableView; frame = (0 0; 414 842); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = ; layer = ; contentOffset: {0, -108}; contentSize: {414, 8702.0000000000109}; adjustedContentInset: {108, 0, 34, 0}; dataSource: <_TtGC7SwiftUIP13$7fff2c6b223419ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2___: 0x7f9d5cf80c50>>

Replies

That error appears the first time SwiftUI uses a list view. It's a general warning not to lay out the table while offscreen, but that's more or less what SwiftUI is doing—they're using a UITableView under the scenes so they can pull coordinates from it, I think.


This is a warning they need to deal with one way or another, but it's benign. You shouldn't be seeing any problems as a result of this. Is your app actually not working properly?

With IOS 13.3 this code doesn't work at all. Specifically, the picker freezes after the first choice is made. Looks like a SwiftUI bug.

Same - not working at all in 13.3 sim