Created
May 31, 2021 07:35
-
-
Save alfianlosari/d5bd934408d59113d8577e7197bde5b5 to your computer and use it in GitHub Desktop.
Main Single Task Async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
static func main() async { | |
// 2 | |
do { | |
// 3 | |
let ipifyResponse: IpifyResponse = try await fetchAPI(url: IpifyResponse.url) | |
print("Resp: \(ipifyResponse)") | |
// 4 | |
let freeGeoIpResponse: FreeGeoIPResponse = try await fetchAPI(url: FreeGeoIPResponse.url(ipAddress: ipifyResponse.ip)) | |
print("Resp: \(freeGeoIpResponse)") | |
// 5 | |
let restCountriesResponse: RestCountriesResponse = try await fetchAPI(url: RestCountriesResponse.url(countryCode: freeGeoIpResponse.countryCode)) | |
print("Resp: \(restCountriesResponse)") | |
} catch { | |
// 6 | |
print(error.localizedDescription) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment