I'm trying to grab a string from a textfile and test the contents of it and return a Bool if it is equal to something. I can't figure out how to return the Bool and keep getting an error message.
Cannot convert return expression of type 'Task<Bool, any Error>' to return type 'Bool'
func checkStatus() {
if test() {
//// do this
}
}
func test() -> Bool {
Task.init {
myResult = try await grabString()
if myResult == "ConnectionOK" {
return true
}
return false
}
}
func grabString() async throws -> String {
var myString: String = ""
let url = URL(string: "https://www.blah blah blah.txt")
if let url = url {
let req = URLRequest(url: url)
let (data, _) = try await URLSession.shared.data(for: req)
myString = String(data: data, encoding: .utf8)!
}
return myString
}
}