SwiftUI won't register code elements in the editor

Hello all,


I am trying to follow the guide - SwiftUI Essentials: Building Lists and Navigation.


However, every time I try to run the preview, I am flagged with "Use of undeclared type 'LandmarkRow_previews'". This is after the very first steps of creating a new SwiftUI file and activating the debugger. None of the elements are color coded(i.e. HStack, Text) and only appear in plain white text as if the editor isn't interpreting the code.
The issue is only happening in this starter project file provided by apple. Is there any workaround that comes to mind?
Thanks,
Matt

Replies

Did you import CoreLocation ?

Which XCode version ? Beta 5 ?


You should first upgrade to beta 5 if not.

Sorry, beta 5. Clean install, as well as reinstalling the project files.

Did you already include the declarations: in LandmarkRow.swift

import SwiftUI

struct LandmarkRow: View {
    var landmark: Landmark

    var body: some View {
        Text("Hello World")
    }
}

struct LandmarkRow_Previews: PreviewProvider {
    static var previews: some View {
        LandmarkRow(landmark: landmarkData[0])
    }
}

Yes, that is the exact format of my code.

Sory for the basic question:

- is LandmarkRow_Previews capitalized properly ?

Yes. I've narrowed down the issue. It seems to flag whenever I try to preview a new file.

So, if you quit and reopen XCode, it should work ?


Or simply, do a option -clean build folder (project menu, holding option key down).

Neither worked, sadly. Tried all the above and restarting computer.

Hey, I'm having this same issue. Clean install of beta 5, following the tutorial exactly, getting the same error. Did you happen to have any luck?

Error message is

Use of undeclared type 'LandmarkRow_previews'".


with lowercase _previews.


But the tutorial is

struct LandmarkRow_Previews: PreviewProvider {
    static var previews: some View {
        LandmarkRow(landmark: landmarkData[0])
    }
}

with Uppercase _Previews.


You should search in the project where you have used (if so) _previews

Or try to change

struct LandmarkRow_previews: PreviewProvider {
    static var previews: some View {
        LandmarkRow(landmark: landmarkData[0])
    }
}

with lowercap previews (that would be a bug either in SwiftUI or its tutorial)

I'm getting the same issue, and I am also getting the following error to...


"XCBBuildService unexpectedly quit" with the option to send a report to apple and to reopen.


This is the error report that is generated when I try to run the live preveiw...



use of undeclared type 'LandmarkRow_Previews'


----------------------------------------


failedToBuildDylib: /Users/bazaroff/Library/Developer/Xcode/DerivedData/BuildingListsAndNavigation-gfmaoxuafhsjxqadzpijdbjvbmer/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/BuildingListsAndNavigation.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/x86_64/LandmarkRow.2.preview-thunk.swift:6:11: error: use of undeclared type 'LandmarkRow_Previews'

extension LandmarkRow_Previews {

^~~~~~~~~~~~~~~~~~~~

/Users/bazaroff/Library/Developer/Xcode/DerivedData/BuildingListsAndNavigation-gfmaoxuafhsjxqadzpijdbjvbmer/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/BuildingListsAndNavigation.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/x86_64/LandmarkRow.2.preview-thunk.swift:7:6: error: replaced accessor for 'previews' could not be found

@_dynamicReplacement(for: previews) private static var __preview__previews: some View {

^

/Users/bazaroff/Library/Developer/Xcode/DerivedData/BuildingListsAndNavigation-gfmaoxuafhsjxqadzpijdbjvbmer/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/BuildingListsAndNavigation.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/x86_64/LandmarkRow.2.preview-thunk.swift:15:11: error: use of undeclared type 'LandmarkRow'

extension LandmarkRow {

^~~~~~~~~~~

/Users/bazaroff/Library/Developer/Xcode/DerivedData/BuildingListsAndNavigation-gfmaoxuafhsjxqadzpijdbjvbmer/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/BuildingListsAndNavigation.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/x86_64/LandmarkRow.2.preview-thunk.swift:16:6: error: replaced accessor for 'body' could not be found

@_dynamicReplacement(for: body) private var __preview__body: some View {

^

/Users/bazaroff/Desktop/BuildingListsAndNavigation/StartingPoint/Landmarks/Landmarks/LandmarkRow.swift:20:17: error: use of unresolved identifier 'LandmarkRow'

AnyView(LandmarkRow())

^~~~~~~~~~~

I managed to solve the problem.


I closed Xcode, deleted the relevant folder in DerivedData, and reloaded the project. Resume the preview again and it's working.


To find out the path of DerivedData: share

Thank you very much! I had the same problems but this helped me 🙂


/Håkan