Hello, is there a way to retrieve the class name o...
# multiplatform
a
Hello, is there a way to retrieve the class name of an anonymous class? I have a usecase where I’m passing some objects from Swift to KMP, but when trying to retrieve the class name via
object::class
I only get
class <anonymous>
so calling any of the
::simpleName
or calling
getOriginalClassName
on it just returns null
e
anonymous = no name
a
makes sense, I guess I’m not too sure why the object becomes “anonymous” when in KMP
e
where is it coming from? if it's an object expression (https://kotlinlang.org/docs/object-declarations.html#object-expressions) then it should be anonymous on all platforms
a
It’s an instance of a Swift Class that I pass to a KMP class which accepts
Any
as param. Something like
class Entry(val t: Any)
then if I do
entry.t::class
returns it as anonymous
e
ah, so KClass doesn't work for ObjectiveC/Swift classes. you might need
NSStringFromClass([t class])
or equivalent. I think you can start from
Copy code
t.`class`
but I don't have macos here to test
a
that would be from Swift side right?
e
t.class should work in K/N, although the method name
class
needs to be escaped with backticks (which is difficult to render in Slack markdown). NSStringFromClass might need to be invoked from Swift or Obj-C though, I can't play around with the interop here
👍 1