QWQ
06/26/2025, 10:31 AMcommonMain
module with a var description: String = ""
property. However, when accessing it from Swift, it inexplicably returns the class object's default description instead of the actual string value. Here's a minimal example:
// Kotlin: com.test.data.TestDto.kt
@Serializable
class TestDto {
var title: String = "title"
var description: String = "description"
}
// Swift usage
public func test(_ dto: TestDto) {
print("dto.title => \(dto.title)")
print("dto.description => \(dto.description)")
}
// Actual output:
dto.title => title
dto.description => com.test.data.TestDto@xxxxxxx
The title
property works as expected.
Xcode debugger shows the correct value for description in breakpoints, suggesting the data is present.
Both properties are declared identically in Kotlin (String type with default values).
This behavior specifically affects the description property name. Renaming it (e.g., to desc) resolves the issue, but I need clarity on why this happens and whether it’s related to reserved keywords in Swift/Kotlin interoperability.
Has anyone encountered similar issues with property names like description in KMP? Any insights into underlying causes or workarounds (besides renaming) would be appreciated!QWQ
06/27/2025, 9:06 AM