Issues building HikeView.swift (from SwiftUI Tutorial)

Currently working through the SwiftUI IOS tutorial, "Animating Views and Transitions" section. The instructions say to import the pre-made files downloaded from the tutorial (which I did) but it won't let me preview "HikeView.swift" like the tutorial suggests I should.

I haven't changed anything in the files and have followed the instructions to the tee, but getting "Compiling failed: cannot find type 'HikeView_Previews' in scope" error in HikeView.swift (and all the imported hike files).

/*
See LICENSE folder for this sample’s licensing information.

Abstract:
A view displaying information about a hike, including an elevation graph.
*/

import SwiftUI

struct HikeView: View {
    var hike: Hike
    @State private var showDetail = false

    var body: some View {
        VStack {
            HStack {
                HikeGraph(hike: hike, path: \.elevation)
                    .frame(width: 50, height: 30)

                VStack(alignment: .leading) {
                    Text(hike.name)
                        .font(.headline)
                    Text(hike.distanceText)
                }

                Spacer()

                Button {
                    showDetail.toggle()
                } label: {
                    Label("Graph", systemImage: "chevron.right.circle")
                        .labelStyle(.iconOnly)
                        .imageScale(.large)
                        .rotationEffect(.degrees(showDetail ? 90 : 0))
                        .padding()
                }
            }

            if showDetail {
                HikeDetail(hike: hike)
            }
        }
    }
}

struct HikeView_Previews: PreviewProvider {
    static var previews: some View {
        VStack {
            HikeView(hike: ModelData().hikes[0])
                .padding()
            Spacer()
        }
    }
}

cannot find type 'HikeView_Previews' in scope

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

CompileDylibError: Failed to build HikeView.swift

Compiling failed: cannot find type 'HikeView_Previews' in scope

/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.swift:5:11: error: cannot find type 'HikeView_Previews' in scope
extension HikeView_Previews {
          ^~~~~~~~~~~~~~~~~
/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.swift:17:11: error: cannot find type 'HikeView' in scope
extension HikeView {
          ^~~~~~~~
/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.swift:52:15: error: struct 'HikeView' does not exist in module 'Landmarks'
import struct Landmarks.HikeView
              ^         ~~~~~~~~
/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.swift:53:15: error: struct 'HikeView_Previews' does not exist in module 'Landmarks'
import struct Landmarks.HikeView_Previews
              ^         ~~~~~~~~~~~~~~~~~


==================================

|  BuildInvocationError
|  
|  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -F /Applications/Xcode.app/Contents/SharedFrameworks-iphonesimulator -enforce-exclusivity=checked -DDEBUG -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -target arm64-apple-ios15.2-simulator -Xfrontend -serialize-debugging-options -enable-testing -swift-version 5 -I /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Products/Debug-iphonesimulator -F /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Products/Debug-iphonesimulator -emit-localized-strings -emit-localized-strings-path /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64 -c -j10 -serialize-diagnostics -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Landmarks-generated-files.hmap -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Landmarks-own-target-headers.hmap -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Landmarks-all-target-headers.hmap -Xcc -iquote -Xcc /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Landmarks-project-headers.hmap -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Products/Debug-iphonesimulator/include -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/DerivedSources-normal/arm64 -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/DerivedSources/arm64 -Xcc -I/Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/DerivedSources -Xcc -DDEBUG=1 -working-directory /Users/tanneruzzell/Documents/allLandmarks/Landmarks /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.swift -o /Users/tanneruzzell/Library/Developer/Xcode/DerivedData/Landmarks-guhrvqwgtxuqateskzhehtsfexkf/Build/Intermediates.noindex/Previews/Landmarks/Intermediates.noindex/Landmarks.build/Debug-iphonesimulator/Landmarks.build/Objects-normal/arm64/HikeView.1.preview-thunk.o -module-name Landmarks_PreviewReplacement_HikeView_1 -Onone -Xfrontend -disable-modules-validate-system-headers -gline-tables-only

Any help is appreciated!

Perhaps there is a problem with your Hike.swift?
Could you share the code for that?

Or maybe...
When you were adding the files to your project, did you check:

  • Copy items if needed
  • Add to targets {Landmarks}

Test:

  • Select the file "HikeView.swift"
  • In the file Inspector...
  • ...make sure "Target Membership" shows a tick by "Landmarks"

Issues building HikeView.swift (from SwiftUI Tutorial)
 
 
Q