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

OR-5242 Practice URLSession #68

Merged
merged 2 commits into from
Apr 4, 2023
Merged

OR-5242 Practice URLSession #68

merged 2 commits into from
Apr 4, 2023

Conversation

crazymanish
Copy link
Owner

Context

In this PR

  • Practice URLSession

Testing steps

  • Git checkout this pr git-branch
  • Open the project and cmd+u

@crazymanish crazymanish requested review from buh and raihan April 3, 2023 18:40
@crazymanish crazymanish merged commit 5b2c3c2 into main Apr 4, 2023
@crazymanish crazymanish deleted the OR-5242-p2 branch April 4, 2023 17:48
crazymanish added a commit that referenced this pull request Apr 4, 2023
* main:
  OR-5242 Practice `URLSession` (#68)
crazymanish added a commit that referenced this pull request Apr 4, 2023
* OR-5242-p2:
  OR-5242 Practice `URLSession` (#68)
func testURLSessionPublisher() {
let expectation = XCTestExpectation(description: "Fetching GitHub user info")

publisher.sink { [weak self] completion in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the convenient method:

URLSession.shared.dataTaskPublisher(for: url).sink { [weak self] completion in

Comment on lines +23 to +26
let apiURL = URL(string: "https://api.github.com/users/crazymanish")
let urlRequest = URLRequest(url: apiURL!)
urlSession = URLSession.shared
publisher = URLSession.DataTaskPublisher(request: urlRequest, session: urlSession)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using real request, please take a look URLProtocol, e.g.
https://www.theinkedengineer.com/articles/mocking-requests-using-url-protocol
or https://www.google.com/search?q=mock+urlprotocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants