SwiftUI Landmark tutorial - keypath not compiling

I'm going through the SwiftUI tutorial: https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation.

The following example code doesn't compile:

List(landmarkData, id: \.id) { landmark in

The error points to the \.id and says: Type '_' has no member 'id'. The landmarkData is [Landmark] and Landmark does have a property id: Int.

I tried:

List(landmarkData, id: \Landmark.id) ...

And get a different error: Cannot convert value of type 'WritableKeyPath<Landmark, Int>' to expected argument type 'KeyPath<_, _>'

Any ideas? This is Xcode 11, beta 6.


I just downloaded this tutorial and built it using Xcode 11, beta 6 without any problems. Try to "Clean Build Folder" before building and retry.

1 Like

The downloaded code doesn't use the keypath. They show it in the tutorial, but change it in a later step.

That said, I did just get it to compile. I had an empty view inside the List { } block. I'd say it's a buggy error message.

Are you asking about step 1 of section 5? I believe it's intentional that that step doesn't compile; that's why there's no preview associated with it. And the next step says "Complete the list by…".

I agree that the error message is opaque.

Yes, that's the step. I thought I was getting an error even when I had something in the block, after the second step, but maybe not. This beta of Xcode is still doing some weird things.

Terms of Service

Privacy Policy

Cookie Policy