Hi! Let's say I have kotlin data class `data class...
# kotlin-native
s
Hi! Let's say I have kotlin data class
data class DataClassTest(val foo: String = "foo", val bar : Int = 1)
So in kotlin code I can initialize it with default properties like
DataClassTest(foo = "bar")
But when I try to use it the same way in swift
DataClassTest(foo : "bar")
I get an error "Cannot invoke initializer for type 'DataClassTest' with an argument list of type '(foo: String)'" Am I missing something?
r
Similar to Java interop, Swift does not see Kotlin's default parameter values
s
This is sad( Is by design or just a missing implementation? Swift's default initializers are look very similar to Kotlin's default parameters..
K/N interop page has this statement
Kotlin constructors are imported as initializers to Swift/Objective-C.
So, in this context default args != initializers, correct?
r
Initializers there means
init()
methods in Swift/Obj-C
For default parameters, I think it's because Obj-C doesn't have them, so Kotlin doesn't see them. Kotlin's Swift interop is only through Obj-C.
s
Initializers there means
init()
methods in Swift/Obj-C
ah, thanks, good to know
For default parameters, I think it's because Obj-C doesn't have them, so Kotlin doesn't see them. Kotlin's Swift interop is only through Obj-C.
Interesting.. That means we wont get any Kotlin goodies that ObjC doesn't have?
o
not exactly, more correct would be statement that in Kotlin code visible to Swift only mechanisms available in Objective-C interop could be present (note, for example,
swift_name
attribute in generated headers)
s
Thanks Nikolay! Where can I read/watch more about this interop inner kitchen since official /objc_interop.html page doesn't go into much details..
l
so, Java doesn’t get default parameters either, but
@JvmOverloads
is a thing
any prospect of similar approaches for objc/swift interop?
s
Similar approach can eventually become available.