Skip to content

A simple wrapper around urlSession data task using the Result type

Notifications You must be signed in to change notification settings

jjnino/url-session-result

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

url-session-result

A simple generic wrapper around URLSession data task using the Result type and Codable.

It allows for a cleaner api by returning the expected decoded Codable object or an error. For example, fetching a user might look like:

URLSession.shared.dataTask(with: URL(string: "https://reqres.in/api/users/2")!) { (result: Result<UserData, Error>) in
    switch result {
    case .success(let userData):
        print(userData.data.first_name)
    case .failure(let error):
        print(error)
    }
}.resume()

Check out the playground to give it a try! Want to use it? Just copy the URLSession extension into your project!

About

A simple wrapper around urlSession data task using the Result type

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages