Add Pull To Refresh to your iOS app using Swift

Last updated on: May 27, 2023

Today, I’ll show you how to add Pull To Refresh into your UITableView/UICollectionView very easily.

Adding Pull To Refresh in TableView/CollectionView

We already have an UITableView/UICollectionView filled with data, and we want to add the Pull To Refresh feature.

The only thing we have to do is to create an UIRefreshControl and add it to our UITableView/UICollectionView and trigger a method, to refresh the data, every time we swipe down.

var refControl = UIRefreshControl()
    override func viewDidLoad() {
        // Setting up UIRefreshControl
        refControl.tintColor = UIColor.white
        refControl.addTarget(self, action: #selector(handleRefresh(refreshControl:)), for: UIControl.Event.valueChanged)

        // ...

    @objc func handleRefresh(refreshControl: UIRefreshControl) { .now() + .seconds(1)) { // We add a 1-second delay for the pull to refresh animation because the UI will glitch otherwise and won't look nice
            // Refresh the data here
            DispatchQueue.main.async {
    }Code language: Swift (swift)
You can find the final project here

If you have any questionsplease feel free to leave a comment below

Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments