I have a function that gets some data from API, but I can’t find why it runs code lines in wrong order
func addFriend(withEmail email: String, firstName: String, lastName: String) async throws {
guard !email.isEmpty else {
return
}
let objectToSend = RegisterSpenderStruct(firstName: firstName, lastName: lastName, email: email)
print("ts1")
networkManager.makeAPIRequest(with: Urls.baseURL + Urls.spenderCreateURL, objectToSend: objectToSend, method: .post, objectType: Spender.self) { (result: Result) in
switch result {
case .success(let object):
print("object id (object.id ?? "")")
print("ts2")
case .failure(let error):
print(error)
}
}
print("ts3")
}
when I run this code in Xcode, I find this statements in console
ts1
ts3
object id 1ac38ac1-5616-451c-8ed4-eec93a54524f
ts2
It seems to me that a part of code works in async mode, but I can’t fix it
I tried to run other part of code in closure, and it works fine, but a have to understand my code why it works like this