Understanding SwiftUI's ViewModifiers and ViewBuilders

It has been more than a year since the release of SwiftUI, and we certainly had some interesting experiences with it so far. It can create a lot of  excitement, surprise, and sometimes a ton of annoyance too. If you have started making apps with SwiftUI, you might have encountered situations where if you used UIKit, the work would be done easily, but with SwiftUI it can sometimes take all day – even more. But since SwiftUI is still a baby, these things shouldn't stop one from learning and unwrapping its mysteries because, with time, it will grow, get better and make our app development way easier.

In this article, we are going to learn two of the key components of SwiftUI, which are ViewModifiers and ViewBuilders. ViewModifiers play a significant role in SwiftUI. Most of the functions called on a SwiftUI View are view modifiers. It is the primary way of modifying a view in SwiftUI. As for ViewBuilders, it is mainly used to create custom container views, which can also become a reusable view component.

In this post, we will take a look at some ready-to-use modifiers, then we will build our own custom view modifier and create a reusable custom container view with ViewBuilder. Using this we can implement gorgeous design systems that are consistent across the entire app and encourage code reusability and good architectural patterns.

Read more

Introducing Diffable Data Source

Ever since the evolution of iOS SDK, it has been the responsibility of the data source, to provide the table-views and collection-views with the data they need to create, configure and display its cells and supplementary views. For this, we are required to implement the necessary protocol (UITableViewDataSource or UICollectionViewDataSource) methods and sync our updated data-model with the data source properly to avoid any synchronization bugs. This approach has been used for a decade now but still, it has quirks and fallout which could sometimes give you a headache.

With iOS 13.0, Apple provided a couple of really cool API’s for both table-views and collection-views. One of these cool features is Diffable Data Sources. In today’s article, I will show you how to use UICollectionViewDiffableDataSource to drive your collection-views. By the end of this article, you will know exactly how to use Diffable Data Sources and what their caveats are. But before that let’s discuss and understand why Apple had to provide a brand new API for data sources. Let’s dive in!

Read more

What's New in Core Location

Apple showcased a lot of major changes in WWDC19, with SwiftUI creating a lot of buzz among the developers. But there were also some other changes that are important and will be affecting the user experience right now. One of them is the updates in the Core Location framework.

iOS 13 improves user privacy related to location sharing. If your app needs the location of the user to recommend or display content, you may need to investigate if your app is still running properly.

Starting from iOS 13, users will be getting a new option to share their location just once. They’ve also empowered While in Use permission and changed many other things. Assuming that you have already worked with Core Location before, let's discuss the updates in detail.

Read more

Customizing Layout for UICollectionView

Almost every application contain a list screen where a vertical/horizontal list of scrollable items is used. Except a few, almost all cases can be fulfilled either by a TableView, or a CollectionView using Flow-Layout. In this post, we will be working on one of such few cases, creating a Custom CollectionView Layout for implementing a Mark-Sheet layout, showing user’s achieved marks in their respective subjects like:

Read more