Could not find landmarks in scope.

Hi,

I am using Swift UI tutorial and now I am on Customize the Row Preview. This is my code:

LandmarkRow(landmark: landmarks[1]) 

I am getting an error "Could not find 'landmarks' in scope. Any suggestions?

Thanks!
sorry but could it be that your code should be:

landmarRow(landmark: landmark[1])

just without the "s"?
In some parts of the project , they use landmarkData
Code Block
let landmarkData: [Landmark] = load("landmarkData.json")

So check your code, maybe have to be
Code Block
            LandmarkRow(landmark: landmarkData[0])

I am using Swift UI tutorial

It was better if you could clarify which tutorial you are using.

I guess it's -- Building Lists and Navigation.

In Step 10 of Section 1 Create a Landmark Model,
you need to add this line to ModelData.swift:
Code Block
var landmarks: [Landmark] = load("landmarkData.json")


Have you done it successfully?
Thank you everyone!

I just had the same issue. They forgot to put modelData. with landmarks.filter

 modelData.landmarks.filter { landmark in

The variable is created in modelData.swift and is called at the top of LandmarkLists.swift

 @EnvironmentObject var modelData: ModelData

Hope this helps!
Many Thanks, srt818071  That post solved the issue I was having with this part of the tutorial.

Thanks Again,
Gibby.

If you follow the tutorial but do not move Landmark.swift into the new Model group, XCode may not recognize that Landmark.swift is part of the project. Moving Landmark.swift into the Model group will fix the problem if that was the cause.

So what's the answer? I still can't figure it out

add this code

var landmarks: [Landmark] = load("landmarkData.json") inside of modeldata.swift

Adding the var landmarks: [Landmark] = load("landmarkData.json") line to the modeldata.swift works, but doesn't this defeat the purpose of using a variable filename (which should come from the main bundle) in the load function? I am new to Swift so I may be missing something here.

Hey, I had exactly the same problem as you mentioned in the question. Note that in the Landmark.swift file you did everything as in the manual and wrote correctly For more bits delete the same code in the Landmark.swift file and copy the following code

import Foundation import SwiftUI import CoreLocation

struct Landmark: Hashable, Codable { var id: Int var name: String var park: String var state: String var description: String

private var imageName: String
var image: Image {
    Image(imageName)
}

private var coordinates: Coordinates
var locationCoordinate: CLLocationCoordinate2D {
    CLLocationCoordinate2D(
        latitude: coordinates.latitude,
        longitude: coordinates.longitude)
}

struct Coordinates: Hashable, Codable {
    var latitude: Double
    var longitude: Double
}

}

I've stumbled upon this problem during learning process and found a solution. In the Code section of the tutorial there is a line missing in the LandmarkRow_Previews function:

static var landmarks = ModelData().landmarks

Which is actually pretty crucial :) After adding, landmarks are in scope of this function.

let land

Could not find landmarks in scope.
 
 
Q