Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift Async #720

Closed
wants to merge 1 commit into from
Closed

Swift Async #720

wants to merge 1 commit into from

Conversation

maxxfrazer
Copy link
Contributor

@maxxfrazer maxxfrazer commented Aug 4, 2023

  • Added async option for Swift code snippet options.
    • Default as false, traditional completion handler style.
  • Changed EXIT_SUCCESS on existing version to EXIT_FAILURE where it actually fails.

The async code looks like:

do {
    let (data, response) = try await URLSession.shared.data(for: request)
    print(String(data: data, encoding: .utf8)!)
    exit(EXIT_SUCCESS)
} catch {
    print("A URL error occurred: \(error)")
    exit(EXIT_FAILURE)
}

Current non-async code:

let task = URLSession.shared.dataTask(with: request) { data, response, error in 
    guard let data = data else {
        print(String(describing: error))
        exit(EXIT_FAILURE)
    }
    print(String(data: data, encoding: .utf8)!)
    exit(EXIT_SUCCESS)
}

IMO the async method should be default, but wanted to get your feedback first!

I have noted in ADDITIONAL_DEPENDENCIES.md that the swift version should be a minimum of 5.5 (released Sept 2021)

@maxxfrazer
Copy link
Contributor Author

@dhwaneetbhatt @SahilChoudhary22 you helped me with my last Swift codegen update, hopefully you see this as an improvement too!

@maxxfrazer
Copy link
Contributor Author

TIL await URLSession.shared.data isn't available on linux? will take a deeper dive.

@maxxfrazer
Copy link
Contributor Author

Going to skip this PR. Unfortunately async isn’t available on Linux exactly the same way as it is for iOS/macOS etc.
I think a huge majority of Swift developers would benefit from it, but unfortunately not all of them.

@maxxfrazer maxxfrazer closed this Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant