ViewBuilder for Conditional Views

@ViewBuilder lets you return different views based on logic inside a single view container, which helps with organizing code better in complex scenarios. Return OS version-specific view: We can also return views based on the iOS version. We can use #available macro to check the system version. Return platform-specific view: We can also return views … Read more

Async Await in Swift & SwiftUI

Async await is part of Swift concurrency. If you are new to concurrency, you should read this article first: Concurrency In Swift. async/await allows us to write asynchronous code in Swift. It enables us to define asynchronous functions and manage concurrency in a way that looks like synchronous code. So code becomes more readable and … Read more

Write Your First MacOS App Using SwiftUI

Developing software for MacOS required a Mac and Xcode. If you don’t have Xcode installed on your Mac, download Xcode and then install it, and then follow these steps. Set Up the Project If you select SwiftUI as Interface, you will able to see the output on the right side of the Xcode. You can run … Read more

ObservableObject in SwiftUI

ObservableObject is a protocol in SwiftUI that enables a class to be observed for changes. When an object conforms to ObservableObject, it can broadcast changes to its properties so that SwiftUI views can update themselves automatically when these properties change. Key Features of ObservableObject: How to Use ObservableObject: Define a Class Conforming to ObservableObject: Create … Read more

Difference between StateObject and EnvironmentObject

Both @StateObject and @EnvironmentObject are property wrappers in SwiftUI used to manage and observe ObservableObject instances. They serve different purposes and are used in various scenarios. @StateObject Purpose: When to Use: How to Use StateObject: When we need to use a StateObject in another view, we had to pass it. But if we use EnvironmentObject, … Read more

Add Firebase Authentication to your SwiftUI App

We can use Firebase Authentication on any SwiftUI app like iOS, macOS, etc. To use Firebase Authentication, first, we have to configure Firebase to our SwiftUI project. For detailed instructions, follow this tutorial: Configure Firebase with SwiftUI. Then follow these steps to use Firebase Authentication: Enable Authentication in the Firebase Console After creating a project … Read more