This is my first Xcode application, I'm building a simple MacOS chatbox application that uses python scrips, PythonKit, and swift to handle serverSide operations and accessing open's api and is meant to trigger these two methods I have in a function called executeProcess() that is meant to invoke other functions in another file when a question is types in the text field and the 'enter' key on a keyboard is hit via the onCommit function, however im getting no console output. here is my relevant code from my contentView.swift file I can provide more code from other files if needed.(I will just be showing the non SwiftUI specific code here)
import Cocoa
import Foundation
import PythonKit
import AppKit
protocol runPyRunnable {
func runPyServer(completion: @escaping(String) -> Void)
func sendRequest(userInput: String, completion: @escaping(String) -> Void)
}
func runPyServer() -> String {
print("server run")
return "server run"
}
struct MyPyTypePlaceHolder: runPyRunnable {
func runPyServer(completion: @escaping(String) -> Void) {
}
func sendRequest(userInput: String, completion: @escaping (String) -> Void) {
}
}
struct ContentView: View {
var ViewController: runPyRunnable? = MyPyTypePlaceHolder() as? runPyRunnable
@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)
}
}
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
}
if let myPyTypeInstance = self.ViewController {
myPyTypeInstance.runPyServer { responseFromRunPyServer in
myPyTypeInstance.sendRequest(userInput: input) { responseFromSendRequest in
completion(responseFromSendRequest)
}
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}