SwiftUI MVVM with practical examples

5 min readMVVM – the Model View ViewModel architecture, is a better design approach for application to ensure there is no tight coupling between your application UI, business logic and the data layer. So, any future changes of any of these components should not affect one another.
Handy withNavigationView() custom modifier for SwiftUI – to add navigation capabilities when needed

5 min readIn SwiftUI, a screen must have a NavigationView in order for it to be able to push to another screen. For example in the diagram below, Screen 1 contains a NavigationLink embedded in a NavigationView, will push to Screen 2 when tapped. And Screen 2 also has a NavigationLink, will push to Screen 3 when […]
Navigation bar title style, color and custom back button in SwiftUI

5 min readWe’ve seen how to simply create NavigationView and NavigationLink in SwiftUI to allow you to push and pop screens. Now, we look at how we can set the title, change the navigation bar color and the back button etc.
How to create custom View modifiers for better code reusability in SwiftUI

5 min readSwiftUI View comes with a range of built-in modifiers, such as background(), frame(), cornerRadius(), shadow() etc, which allow you to change the view from its original appearance or behaviour. Besides the built-in modifiers, you can also create your own custom modifiers.
How to use function that returns some View to increase SwiftUI code readability

3 min readTo have better readability for my SwiftUI code, I’ll always move some complex parts in my SwiftUI code to some dedicated functions. Especially those parts that need to display different views on different conditions.
Push and pop screens with NavigationView in SwiftUI

4 min readIn iOS development, we always have our apps designed in a way letting users to navigate between screens. Such as in the UIKit, a UINavigationController is used to push to another ViewController and pop back from it.
Useful extension functions to decode Json from Bundle and remote URL with SwiftUI examples

5 min readHere are two useful extension functions for decoding Json data into structs or objects of any type. The first one is an extension function of Bundle for decoding any JSON file stored in your local bundle. The second one is an extension function of URLSession for decoding any JSON data from remote URL.
JSON parsing and examples of creating views in loop with SwiftUI

4 min readMost of our apps need to deal with JSON parsing these days. Especially when your apps need to load data from REST API which provides data in the form of JSON. With SwiftUI, the use of ForEach and List that allow the creation of views in a loop with ease, making it better to have […]
Creating views in a loop with ForEach, Identifiable and List in SwiftUI

2 min readIn SwiftUI, you cannot use a control flow statement within a ViewBuilder closure. For example, you need to loop over a collection of data and create views accordingly. The screenshot below shows that a typical for loop in swift code is used but your Xcode will show you error as below.
List and ScrollView in SwiftUI

3 min readIn UIKit, we use UITableView to display a single-column, vertical and scrollable rows of contents and UIScrollView to display contents that will not fit entirely on the screen, which then allows them to be scrollable either horizontally and vertically.