Fix Those Annoying Separator Lines in Swift
Difficulty: Beginner | Easy | Normal | Challenging
The supporting video
Missing the wonderful diagrams below, but this video might be of interest to you!
- You will be expected to be aware how to make a Single View Application in Swift.
Async download images
It is important to download images asynchronously. This can be placed in an extension, as follows:
That looks great!
But what about…The images do not appear
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.
But what about…The separator lines
the separator lines do not fill the whole screen. However, this is an easy fix!
tableView.separatorInset = .zero
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