There are multiple answers on StackOverflow already answering your specific use case. For example have a look at this question: get progress from dataTaskWithURL in swift
For your specific use case there are also already answers using AFNetworking: AFNetworking 3.x multipart form upload
To summarize, what you want to do is to
1. calculate the total amount of data you want to upload and the
2. total amount of data you already uploaded via the URLSession
delegate methods.
Then you can bind this information to your UI element, for example your UIProgressView
. Make sure that your upload tasks are asynchronous in order to have a non blocking upload task and to be able to update your UI while the upload is happening. This also means that other than your upload task your code to refresh the UI should run on the main thread. You can enforce this via DispatchQueue.main.async
if needed.