Previewing your app’s interface in Xcode

//
//  ContentView.swift
//  HardApp
//
//  Created by Besleaga Alexandru Marian on 14.06.2024.
//

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

// A SwiftUI preview.
#Preview {           Use of unknown directive '#Preview'
    // The view to preview.
}

I'm trying to learn Xcode and got stuck on these error that I receive when trying to apply the macro #Preview, how can declare the directive so I can use it in my own code for the preview it offers ?

Kind Regards

Which version of Xcode do you use ? #Preview is available only in Xcode 15 and over.

If you use an older version, replace

#Preview {      
    // The view to preview.
}

by:

struct ContentView_Previews: PreviewProvider {
    
    static var previews: some View {
        ContentView()
    }
}
Previewing your app’s interface in Xcode
 
 
Q