Apr 20, 2024 iOS

Perform a deeplink from SwiftUI widget on tap

Performing a deep link from a SwiftUI widget on tap involves several steps. Widgets in SwiftUI are limited in their interactivity compared to full app views, but you can still use them to open your app and navigate to a…

Apr 19, 2024 iOS

Get the current scroll position of a SwiftUI ScrollView

Certainly! In SwiftUI, you can obtain the current scroll position of a ScrollView using various techniques. Let’s explore a couple of approaches: Using GeometryReader and PreferenceKey: You can track the scroll position by using a custom PreferenceKey. Here’s an example: struct DemoScrollViewOffsetView: View { @State private…

Apr 18, 2024 iOS

Xcode – How to fix ‘NSUnknownKeyException’, Reason: “… this class is not key value coding-compliant for the key X” error?

I'm trying to link a UILabel with an IBOutlet created in my class. My application is crashing with the following error" *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.'…

Apr 17, 2024 iOS

Can SwiftUI Text Fields work with optional Bindings? 

Yes, SwiftUI TextField can work with optional bindings. However, there are certain considerations to keep in mind when dealing with optional bindings. When you're using an optional binding with a TextField, you need to handle both the case where the…

Apr 16, 2024 iOS

How can I pop to the Root view using SwiftUI?

There are two main ways to pop to the root view in SwiftUI, depending on the version of SwiftUI you're using: For SwiftUI versions before iOS 16: Using environment(\.rootPresentationMode): In the child view where you want to trigger the pop,…

Apr 16, 2024 iOS

How to detect live changes on TextField in SwiftUI?

In SwiftUI, you can detect live changes on a TextField using the .onChange modifier. Depending on the version of SwiftUI you’re using, there are different approaches: SwiftUI 2.0 (iOS 14, macOS 11, etc.): In SwiftUI 2.0, you can directly use the .onChange modifier to detect any change…

Apr 15, 2024 iOS

SwiftUI app life cycle iOS14 where to put AppDelegate code?

In SwiftUI apps targeting iOS 14 and later, you typically won't have an AppDelegate file by default because SwiftUI apps rely on the @main attribute applied to your app's main entry point, usually a struct that conforms to the App…

Apr 14, 2024 iOS

SwiftUI HStack with wrap and dynamic height

In SwiftUI, achieving a horizontally stacked layout with wrapping behavior (similar to UIStackView with UIStackViewDistribution.fillEqually and UIStackViewAxis.horizontal in UIKit) along with dynamic height can be a bit tricky because SwiftUI's built-in layout system doesn't directly support wrapping behavior. However, you…