Im getting a scoping error in the default App.swift file of my Xcode project and ive done everything to try to solve the issue, my ContentView struct is at the top level, ive cleaned the build folder a hundred times, restarted Xcode, cleared the derived data folder for nothing to happen. Here is my ContentView.swift file below.
protocol runPyAndSendRequestRunnable {
func runPyServer() -> String
func sendRequest(inputText: String, completion: @escaping(String) -> Void)
}
func runPyServer() -> String {
print("server run")
return "server run"
}
func sendRequest() -> String {
print("request sent")
return "request sent"
}
struct MyPyType: runPyAndSendRequestRunnable {
func runPyServer() -> String {
return "server started"
}
func sendRequest(inputText: String,completion: @escaping(String) ->Void) {
let userInput = inputText
guard let url = URL(string:"http://localhost:8080/MacGPT") else {
completion("Error: failed to obtain url")
return
}
}
struct ContentView: View {
var viewController: runPyAndSendRequestRunnable? = MyPyType()
@State private var text: String = ""
@State private var filePath = ""
@State private var inputText = ""
var body: some View {
makeContent()
.onAppear{
NSApp.mainWindow?.makeFirstResponder(NSApp.mainWindow?.contentView)
}
}
func makeContent() -> some View {
ScrollView {
HStack {
VStack {
VStack(alignment: .center, spacing: 200) {
makeGlobeImage()
makeSecondLogo()
makeTitle()
makeSubtitle()
makeTextFieldAndEnter()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(maxWidth: .infinity)
}
}
.background(Color.white.opacity(0.9))
.cornerRadius(12)
.padding(.horizontal, 57)
.padding(.bottom, 80)
.frame(minWidth: 1600, minHeight: 1050)
.background(Color.white.opacity(0.1))
.cornerRadius(12)
}
func makeGlobeImage() -> some View {
Image(systemName: "globe")
.foregroundColor(.blue)
.font(.system(size: 40))
.offset(y: 348)
.offset(x: -240)
}
func makeSecondLogo() -> some View {
Image("second Logo")
.resizable()
.scaledToFit()
.frame(width: 90, height: 90)
.offset(x: 185)
.offset(y: 78)
}
func makeTitle() -> some View {
Text("Mac GPT")
.font(Font.custom("Futura", size: 77))
.foregroundColor(Color.black)
.padding(2.15)
.overlay(RoundedRectangle(cornerRadius: 20).stroke(Color.gray, lineWidth: 1.0))
.offset(x: -37)
.offset(y: -221)
}
func makeSubtitle() -> some View {
VStack {
Spacer()
Text("Access the power of AI right from your Mac's homescreen, just for Mac.")
.font(Font.custom("Futura", size: 18.6))
.fontWeight(.bold)
.padding(.vertical, 11)
}
.offset(y: -20)
.offset(x: -40)
}
func makeTextFieldAndEnter() -> some View {
ZStack {
Spacer()
TextField("Ask Mac GPT...", text: $inputText, onCommit: {
executeProcess(withInput: inputText) { response in
print(response)
}
})
.font(Font.custom("Futura", size: 17.4))
.padding(.horizontal, 25)
.padding(.vertical, 15)
.background(Color.white)
.cornerRadius(29)
.overlay(
RoundedRectangle(cornerRadius: 27.9).stroke(Color.gray, lineWidth: 1.0)
)
.offset(y: -200)
.padding(.horizontal, 35)
}
}
func executeProcess(withInput input: String, completion: @escaping (String) -> Void ) {
DispatchQueue.global().async {
DispatchQueue.main.async {
guard !input.isEmpty else {
print("TextField is empty, enter input in the text field")
return
}
self.viewController?.runPyServer() // add closures
self.viewController?.sendRequest(inputText: input) { response in
completion(response)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}
}
-code`