0

Environment: Version 11.0 beta 4 (11M374r)

I'm trying to get a grip on the evolving List() syntax.
The following is a simple list of UUIDs:

enter image description here

via the pre-Beta 4 Code: enter image description here

Here's my attempted remedy and the compiler result.
I've created an additional error after fixing the previous warning: enter image description here

I tried replacing '@State' with '@Binding'; which didn't work.

Here's the complete source code:

import SwiftUI

enum TabIdentifier {
    case list
    case another
}

struct TabView: View {
    private var uuids: [String] = {
        let ids: [String] = Array(0...5).map { _ in
            UUID().uuidString
        }
        return ids
    }()

    @State private var selectedTab: TabIdentifier = .list

    var body: some View {
        TabbedView(selection: $selectedTab) {
            // ------------------------------------------------------------
            // Tab #1
            NavigationView {
                 List(uuids, id: \.id) { uuid in
                    Text(uuid)
                }.navigationBarTitle(Text("List of UUIDs"))
            }.tabItem {
                Text("List") // ...Tab #1 Label
            }
            .tag(TabIdentifier.list) // ...Tab #1 tag
            // ------------------------------------------------------------
            // Tab #2
            Text("Hello Ric!")
                .tabItem {
                    Text("Another view") // ...Tab #2 Label
            }
            .tag(TabIdentifier.another) // ... Tab #2 Label
        }
    }
}

What's the remedy?

Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105

1 Answers1

1

This is a misleading error. I'm pretty sure your issue is just a typo. It should be List(uuids, id: \.self), not List(uuids, id: \.id). Based on your code, uuids is just an array of strings, and String doesn't have a property id.

graycampbell
  • 7,430
  • 3
  • 24
  • 30