This simplifies code and cleans up call-site use, and makes it explicit when to use each helper. When your Kotlin ViewModel StateFlow has non-optional values, use the state helper in SwiftUI. When your StateFlow has an optional type and might have null values, use stateNullable in SwiftUI.
Note: There isn't compiler help when deciding between state and stateNullable in SwiftUI. Choosing state where stateNullable is required will cause a runtime crash due to force unwrapping. Take care to use the correct helper.
This PR also introduces state and stateNullable helpers for KotlinBase. When Kotlin/Native exports to Objective-C, all custom classes share a common KotlinBase interface (which implements NSObject and has isEqual available).
This simplification makes the library slightly easier to use and perhaps a little more intuitive. Instead of forcing callers through state(_:equals:mapper:) for custom types and making them define their own equals and mapper, it's now possible to just use the simpler state(_) helper.
This simplifies code and cleans up call-site use, and makes it explicit when to use each helper. When your Kotlin ViewModel
StateFlow
has non-optional values, use thestate
helper in SwiftUI. When yourStateFlow
has an optional type and might havenull
values, usestateNullable
in SwiftUI.Note: There isn't compiler help when deciding between
state
andstateNullable
in SwiftUI. Choosingstate
wherestateNullable
is required will cause a runtime crash due to force unwrapping. Take care to use the correct helper.This PR also introduces
state
andstateNullable
helpers forKotlinBase
. When Kotlin/Native exports to Objective-C, all custom classes share a commonKotlinBase
interface (which implementsNSObject
and hasisEqual
available).This simplification makes the library slightly easier to use and perhaps a little more intuitive. Instead of forcing callers through
state(_:equals:mapper:)
for custom types and making them define their ownequals
andmapper
, it's now possible to just use the simplerstate(_)
helper.