Hey everyone!
I have some problems getting code to run and think that it has to do with my understanding of how Alamofire and/or Swift works. I am fairly new to Swift but have been programming in other languages for years now so terminology and concepts should (hopefully) be familiar to me.
Now to my problem. I was playing around and tried to create a minimal and rough API client but am failing at the simplest steps it seems. Here is my sample code:
import Foundation
import Alamofire
public struct Client {
private let baseUrl: String = "https://httpbin.org/get"
public func getTest() {
AF.request(baseUrl).response { response in
debugPrint(response)
}
}
import XCTest
@testable import Dolphin
final class DolphinTests: XCTestCase {
func testExample() throws {
let client = Client()
client.getTest()
}
}
So basically I just want to make a simple GET request and print out the response
like in the documentation but I never get an output in my tests. Is this an async
call and the test finishes before the response can be read? What is the best practice in this case anyways? At that point I am just trying to get a minimal request working and mess around with the response so any help is appreciated.