Hi, We have a naming conflict on Swift code which ...
# multiplatform
b
Hi, We have a naming conflict on Swift code which use our Kmp library. Is there a way to prefix all class names which generated by Kmp for iOS/Swift?
j
I think you should be able to use
ObjCName
for that - https://kotlinlang.org/docs/native-objc-interop.html#name-translation
b
ObjCName
can help to transform individual classes, I would do it for every classes in my library
j
Kotlin types are prefixed in Objective-C with a prefix derived from the framework name. But in Swift, the prefix is removed, e.g. (for a framework Foo):
Copy code
__attribute__((swift_name("Bar")))
@interface FOOBar
Because Swift has module namespacing, ObjC's convention for type prefixing is optional in Swift. If you run into a situation where two modules used in the same file have conflicting types, you can use a local typealias to disambiguate, e.g.:
Copy code
typealias AMyClass = ModuleA.MyClass
typealias BMyClass = ModuleB.MyClass
b
That would be an option, but we would like to have the same prefix for every classes from the Kmp library in Swift. It’s easier to keep track
j
I don't believe there's an option to globally prefix all Kotlin types in Swift.
b
We need to use either
ObjCName
annotation and/or Swift’s typealias then. Thanks @Jeff Lockhart, your tips is really helpful