Home > OS >  SwiftUI 4 List initializer not available in iOS
SwiftUI 4 List initializer not available in iOS

Time:07-10

When creating a list, previous versions of Xcode allowed for the following on iOS:

List(tabs, selection: $lastTab) {tab in
…
} 

This now gives an error:

'init(_:selection:rowContent:)' is unavailable in iOS

also true for

List(tabs, id:\.self, selection: $lastTab)

and other variations such as:

List(selection: $lastTab) {
   ForEach(tabs, id:\.self) {tab in 
...
}

Has anyone else run into this problem?

CodePudding user response:

You probably forgot to make selection as Optional, ie.

@State private var lastTab: Int? = 0   // << here !! `Int?`

List(tabs, selection: $lastTab) {tab in
// ...
}

Verified with: Xcode 14b3 / iOS 16

  • Related