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…

Apr 14, 2024 iOS

Call UIKit function from SwiftUI

To call a UIKit function from SwiftUI, you'll typically use a UIViewRepresentable wrapper to create a SwiftUI view that wraps the UIKit component. Within this wrapper, you can call UIKit functions and handle any necessary interactions between SwiftUI and UIKit.…

Apr 13, 2024 iOS

What enables SwiftUI’s DSL?

SwiftUI's Domain-Specific Language (DSL) is enabled by several key language features and design decisions: Swift Language: SwiftUI is built using the Swift programming language, which provides powerful features such as closures, generics, function builders, property wrappers, and protocol extensions. These…