François
12/03/2024, 10:16 AM// On swift side is Int32 (OK)
public var test: Int = 0
// On swift side is SkieSwiftOptionalStateFlow<KotlinInt> (WHY?)
private val _intNullValue = MutableStateFlow<Int?>(null)
public val intNullValue: StateFlow<Int?> = _intNullValue
// On swift side is SkieSwiftStateFlow<KotlinInt> (WHY?)
private val _intNotNullValue = MutableStateFlow(0)
public val intNotNullValue: StateFlow<Int> = _intNotNullValue
So why the stateflow is not SkieSwiftStateFlow<Int32>? same thing for other integer types.Tadeas Kriz
12/03/2024, 2:51 PMStateFlow<Int> in Kotlin, SKIE makes it available using SkieKotlinStateFlow<Int> which produces SkieKotlinStateFlow<KotlinInt> for Objective-C/Swift. Then we bridge that to SkieSwiftStateFlow, but KotlinInt has no direct bridging. So SKIE would have to manually map the type in runtime which has added complexity. This is on our list of possible features, but that list is long, so much to do 😄François
12/03/2024, 3:10 PMTadeas Kriz
12/03/2024, 3:12 PMInt is replaced by Int32 only when it's not in places where NSObject type is required (generics, some lambdas etc)François
12/03/2024, 3:16 PMTadeas Kriz
12/03/2024, 3:35 PMStateFlow with Int32 from Swift? We could take inspiration from itTadeas Kriz
12/03/2024, 3:56 PMInt32 but no observation, or KotlinInt but observing, correct?François
12/03/2024, 3:57 PMFrançois
12/03/2024, 3:59 PMTadeas Kriz
12/03/2024, 4:01 PMNSObject will behave this way. For example even Kotlin's Unit is translated to Swift's Void, but when it's used in generics it'll be KotlinUnit because Objective-C's void is a primitive, same as int32, int64, float etc. It's a limitation of Objective-C generics and pointers. For example the same problem is when you make that Kotlin Int in your VM into Int?. You'll now see KotlinInt? in Swift.François
12/03/2024, 4:08 PMInt and an Int? inside a data class, I got the following : Int32 and KotlinInt?Tadeas Kriz
12/03/2024, 4:10 PMint32 that'd be nullable in Objective-C without making it an object (NSObject). In real Objective-C, we used to just put NSNumber where we needed nullable int32, but Kotlin's doing better by introducing KotlinInt so it's at least visible that it's supposed to be an Int and not any number. Although it's still backed by NSObject (and it's a descendant) so you can call .floatValue on KotlinInt instance and I'll convert it to float, which is weird but again, Objective-C legacy.François
12/03/2024, 4:12 PMTadeas Kriz
12/03/2024, 4:14 PMTadeas Kriz
12/03/2024, 4:14 PMFrançois
12/03/2024, 4:25 PMInt32 and Int32? , so no use of KotlinInt, which is greatTadeas Kriz
12/03/2024, 4:26 PMInt32 is not great for Swift, where you'd want to use just regular Int. But that's a different discussionFrançois
12/03/2024, 4:37 PMFrançois
12/03/2024, 6:26 PM@sharedViewModel(ofType: MainScreenViewModel.self,
publishing:
(\.mainScreenUIState, MainScreenUIState.self),
(\.userId, String?.self),
(\.intNotNullValue, Int.self),
(\.intNullValue, Int?.self)
)
class MyMainScreenViewModel: ObservableObject {}