I’m having a hard time with
companion
and
object
usage inside my Swift code. Let say we have this Kotlin code:
class SomeClass {
companion object {
fun someIntFunction(): Int {
return 1
}
}
}
fun SomeClass.someBoolFunction(): Boolean {
return false
}
fun SomeClass.Companion.toSomeString(): String {
return "to Some String"
}
object SomeOtherStatic {
fun stringStuff(): String {
return "String Stuff"
}
}
And with that Swift code:
let some = SomeClass()
let someBool = some.someBoolFunction()
let someInt = SomeClass.Companion.someIntFunction()
let someString = SomeClass.Companion.toSomeString()
let otherString = SomeOtherStatic.stringStuff()
I get errors from inside Xcode:
Instance member 'someIntFunction' cannot be used on type 'SomeClass.Companion'; did you mean to use a value of this type instead?
I have this error for
someIntFunction
,
toSomeString
and
stringStuff
. The compile thinks they are instance functions 🤔
Is there something I am doing wrong?
Thanks!