ContentView doesn't preview

I am using Xcode 13.2 and the Preview of ContentView does not work. I have macOS Monterey with Intel processor. I get the following error. Would appreciate any suggestion.

unable to execute command: Executable "ld" doesn't exist!



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



LinkDylibError: Failed to build ContentView.swift



Linking failed: unable to execute command: Executable "ld" doesn't exist!



clang-10: error: unable to execute command: Executable "ld" doesn't exist!

clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

I suggest you post your "ContentView" code, then it may be possible to say why it doesn't preview.

I am just using the default code. I have not added any code yet. Problem is probably related to some settings. Please let me know if you need any thing else.

import SwiftUI



struct ContentView: View {

    var body: some View {

        Text("Hello, world!")

            .padding()

    }

}



struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

Thanks for response. I am just using the default code. I have not added any code yet. Problem is probably related to some settings. Please let me know if you need any thing else.

Hi,

Sorry to hear you are having problems getting previews working.

Based upon your description of the situation I am guessing that your xcode installation might be faulty. Would it be possible to attempt to download a new version from https://developer.apple.com/xcode/resources/ ?

SOLVED!

In my case, I was using another Toolchain(that I installed to test another Swift SDK, that doesn't matter now), and all I needed to do is setting the Xcode to use the default Toolchain again:

  1. With the Xcode open, on the MenuBar(top of you screen) click on [Xcode]
  2. Click on [Toolchain]
  3. Click on [Manage Toolchain]
  4. Click/Select your Xcode's version. E.G.: In you case: "Xcode 13.2"

[Extra step] I suggest you to uninstall another Toolchain that is not the default after using it, since Xcode can give some errors difficult to detect/understand, and you can do this by doing a ["Right click of your mouse" on those Toolchains ] -> [Move to Trash]

Tags: @hosshonar

ContentView doesn't preview
 
 
Q