Reputation: 59
Im trying to fix this from a very long time.
I can not understand what to pass to this function in place of "(String) -> void" as it was supposed to return a string :
var result = myobj.createData(request: request, with: (String) -> void)
The above code is calling the following function:
func createData(request:Crudpb_CreateRequest, with completion: @escaping (String) -> Void) {
DispatchQueue.main.async {
self.response = try! self.client.create(request)
completion(self.response.result)
}
}
Upvotes: 2
Views: 565
Reputation: 15748
When you call this function you need to pass a closure with the type (String) -> void
myobj.createData(request: request, with: { string in
print(string)
})
Or
var completion = { string in
print(string)
}
myobj.createData(request: request, with: completion)
You can store the result like this
var result = ""
myobj.createData(request: request, with: { string in
result = string
self.displayTextArea.text = result
print(result)
})
Upvotes: 3