Swift/ Swift UI errors.

Hi everyone, I am a new developer. I am writing some code in swift playgrounds and came across some odd errors. I have looked for solutions and have found nothing. If any more experienced developers could point me in the right direction, that would be great.

Answered by darkpaw in 819516022

MyApp likely has something called ContentView() in it. This means that it wants to display the view called ContentView. You seem to have deleted the lines that define ContentView, so you need to put them back:

import SwiftUI
import AVFoundation

struct ContentView: View {
  var body: some View {
    Button("Greet me") {
      let synthesizer = AVSpeechSynthesizer()
      let utterance = AVSpeechUtterance(string: "Hello World!")
      synthesizer.speak(utterance)
    }
  }
}
Accepted Answer

MyApp likely has something called ContentView() in it. This means that it wants to display the view called ContentView. You seem to have deleted the lines that define ContentView, so you need to put them back:

import SwiftUI
import AVFoundation

struct ContentView: View {
  var body: some View {
    Button("Greet me") {
      let synthesizer = AVSpeechSynthesizer()
      let utterance = AVSpeechUtterance(string: "Hello World!")
      synthesizer.speak(utterance)
    }
  }
}

Thank You so much!

Don't forget to tip your waiter / mark the answer as accepted.

Thank you for replying. I appreciate it. However I am still getting errors:

Swift/ Swift UI errors.
 
 
Q