https://kotlinlang.org logo
s

Simonas Brazauskas

07/30/2021, 1:10 PM
Hello, it seems abstract classes does not force subclassed classes to implement interface methods in swift. For example
Copy code
abstract class KotlinAbstractClass : KotlinInterface {

}

interface KotlinInterface {
    fun testFunction()
}

//Swift code
class SwiftClass : KotlinAbstractClass {
    
}
XCode compiles
SwiftClass
successfully, but then fails with an exception at runtime if someone tries to call
SwiftClass::testFunction
. Is this a bug or works as intended? We are having some issues with ios devs, as sometimes they forget to implement all interface methods, which results in crashes. Also it would cause issues, when additional methods in interfaces are added.
r

rnett

07/31/2021, 12:07 AM
Probably worth a youtrack issue, that does not seem intended
n

Nicklas Jensen

08/03/2021, 8:58 AM
The concept of “abstract classes” doesn’t exist in Swift or Objective-C, and as such, Kotlin’s abstract classes are represented in Swift/Objective-C as a regular class, with method implementations stubbed to throw exceptions.
3 Views