skip to Main Content

I’m learning SwiftUI by following Apple’s tutorial: https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation

in section 2 step 4, when I type in the same code as instructed:

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: landmarks[0])
    }

}

SwiftUI preview is not working(showing nothing) and return the error message:

RemoteHumanReadableError: Failed to update preview.

The preview process appears to have crashed.

Error encountered when sending 'previewInstances' message to agent.

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

|  RemoteHumanReadableError: The operation couldn’t be completed. (BSServiceConnectionErrorDomain error 3.)
|  
|  BSServiceConnectionErrorDomain (3):
|  ==BSErrorCodeDescription: OperationFailed

I have even tried to copy paste Apple’s example code and preview not work either.
Although other SwiftUI views in the earlier tutorial sessions work fine, I suspect it might relate to the preview provider struct at end of code and I searched online but no helps.

here’s my app ver:

Xcode ver: 12.5 (12E262)
MacOS ver: 11.3.1 Big Sur

I can not continue my study until this issue has been resolved.
Any inputs are appreciated, thanks in advance.

2

Answers


  1. Chosen as BEST ANSWER

    strangely, the issue was gone after I start the tutorial all over from the beginning. SwiftUI Preview works as expect now


  2. Maybe in your code snippet you’ve just missed some bits out, as that code shouldn’t copmile. You’ve pointed to an array called landmarks, but doesn’t look like you’ve created the array object for you preview to use. This should work:

    struct LandmarkRow_Previews: PreviewProvider {
    
        static var previews: some View {
    
            LandmarkRow(landmark: Landmark())
        }
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search