I have an iOS app that uses URLSession.shared.data in multiple places. I would like to be able to create the functionality to log the request and response data to the console. I have created functions to do this logging, but I currently would have to add this function to all places in the app that use URLSession.shared.data. Is there a way to create an extension on URLSession to be able to log data once the response is received?
Log request and response data from URLSession
179 views Asked by travis At
1
I would suggestion you make your own network layer instead of using
URLSession.shared.datadirectly. Mainly because with that it hard to implement unit tests.But you can make something like this:
Then you need to make your own URLSession like this: