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.

1 Like

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.

@robnik Did you manage to fix this?

I've ran into the exact same issue but I am having no luck correcting it.

I think I was only getting that error when I had another error within the closure block below it. The problem is that a bug in the compiler causes it to report the error there, at the top of the block, even if the real error is 50 lines later. So both the error location and message are completely misleading. This and some other issues with runtime layout bugs, and lack of documentation, led me to abandon SwiftUI for now.


this drove me insane. thank you for the hint with the well-known-wrong error-messages.
Somehow XCode created a List { ... } around my List(...) { ... }, what I didn't realize on the first hundred sights... 8-)

that's right, returning LandmarkRow(landmark: landmark) from the closure made error go pass.

As @nylz said, we just had to look for the some another line for the exact error location as it always happens in Xcode.

Terms of Service

Privacy Policy

Cookie Policy