May 02, 2024 iOS

SwiftUI 2: the way to open view in new window

In SwiftUI 2 and later, you can use the WindowGroup and Window APIs to open views in new windows. This allows you to create multi-window experiences in your SwiftUI app. Here's how you can open a view in a new…

May 01, 2024 iOS

How to scroll List programmatically in SwiftUI?

Certainly! In SwiftUI, if you want to programmatically scroll a List to a specific position, you can use the ScrollViewReader. This provides a scrollTo() method that allows you to move to any row inside the list by providing its ID and optionally an anchor12. Here’s how…

Apr 30, 2024 iOS

Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

Certainly! Auto Layout can be used in UITableView to create dynamic cell layouts with variable row heights. This is particularly useful when the content within the cells varies in length and you want the cells to adjust their height accordingly.…

Apr 30, 2024 iOS

How to get the index of the element in the List in SwiftUI when the List is populated with the array?

Certainly! In SwiftUI, you can use the enumerated() function to get the index when looping through a List. Let’s explore how to achieve this: Suppose you have an array of items that you want to display in a List along with their corresponding indices. Here’s…

Apr 29, 2024 iOS

SwiftUI HStack with Wrap

Explore Certainly! SwiftUI provides an HStack for arranging views horizontally, but if you need to handle overflowing elements by automatically positioning them on the next lines, you might want to explore a custom solution. Here are a few options: WrappingHStack…

Apr 28, 2024 iOS

Calling functions from UIViewController in SwiftUI

Certainly! When working with SwiftUI, you might need to interact with functions from a UIViewController. Let’s explore a few approaches to achieve this: Using ObservableObject and Coordinator: Create an ObservableObject (let’s call it VCLink) to act as a bridge between your SwiftUI view and…

Apr 28, 2024 iOS

Share data between main App and Widget in SwiftUI for iOS 14

To share data between the main app and a widget in SwiftUI for iOS 14, you can use App Groups and UserDefaults to store and retrieve shared data. Here's a step-by-step guide on how to do it: 1. Enable App…

Apr 27, 2024 iOS

SwiftUI – How to pass EnvironmentObject into View Model

Certainly! When working with SwiftUI, you can pass an EnvironmentObject into a view model to share data across your app. Here are the steps to achieve this: Create an Environment Object: First, create an environment object that holds the data you want…