Fix Those Annoying Separator Lines in Swift

Difficulty: Beginner | Easy | Normal | Challenging

Missing the wonderful diagrams below, but this video might be of interest to you!

Prerequisites:

The setup

It is important to download images asynchronously. This can be placed in an extension, as follows:

That looks great!

These images do not appear! This is because cell.imageView is optional, and the asynchronous nature of downloading an image to the ImageView does not hold a reference to the ImageView for sufficient time until the image is downloaded. The solution? Use a placeholder image:

cell.imageView?.image = UIImage(named: “placeholder”)

where I’ve used a placeholder image in the asset catalogue.

the separator lines do not fill the whole screen. However, this is an easy fix!

tableView.separatorInset = .zero

Conclusion

This is important stuff! You would want to lazily load images in a great deal of situations for creating Apps that are production ready. Before letting your users loose on your application you would like a great user experience. That is, you would really need to use lazy loading for your images.

If you’ve any questions, comments or suggestions please hit me up on Twitter

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store