![]() ![]() Kotlin has no concept of checked exceptions, all Kotlin exceptions are unchecked. Use the annotation that instructs the Kotlin compiler to use a custom Objective-C and Swift name for methods or parameters. You can specify a more idiomatic name in Swift or Objective-C, instead of renaming the Kotlin declaration. The methods of kotlin.Any ( equals(), hashCode() and toString()) are mapped to the methods isEquals:, hash and description in Objective-C, and to the method isEquals(_:) and the properties hash, description in Swift. Each Kotlin file is translated into such a class. Top-level Kotlin functions and properties are accessible as members of special classes. The same goes for a protocol's read-only properties that are implemented as mutable. Writeable Objective-C properties overriding read-only properties of the superclass are represented as setFoo() method for the property foo. Kotlin constructors are imported as initializers to Swift/Objective-C. The latter happens with initializers declared in the Objective-C category or as a Swift extension, because Kotlin has no concept of extension constructors. Swift/Objective-C initializers are imported to Kotlin as constructors and factory methods named create. It instructs the Kotlin compiler to use a custom Objective-C and Swift name for classes, interfaces, and other Kotlin = "MySwiftArray")Ĭlass MyKotlinArray element: String): Int = TODO() To avoid renaming Kotlin declarations, use the annotation. To work around this, you can rename the conflicting Kotlin classes in the framework. ![]() This algorithm is not stable yet and can change between Kotlin releases. If the Kotlin compiler finds Kotlin classes in the same framework which have the same name but different packages, it renames them. Objective-C does not support packages in a framework. The prefix is derived from the framework name. The names of Kotlin classes and interfaces are prefixed when imported to Objective-C. These classes and interfaces are placed into a package specified in build configuration ( platform.* packages for preconfigured system frameworks). ![]() ![]() "->" and "<-" indicate that mapping only goes one createĬompanion member interface FooProtocol. The table below shows how Kotlin concepts are mapped to Swift/Objective-C and vice versa. You can still use these declarations in your Swift code to create a Swift-friendly API, but they won't be suggested in the Xcode autocomplete.įor more information on refining Objective-C declarations in Swift, see the official Apple documentation. Such declarations get the _ prefix, which makes them invisible from Swift. The annotation marks a function or property as swift_private in the generated Objective-C API. The annotation disables a function or property export to Objective-C, making your Kotlin code more helps to replace a Kotlin declaration with a wrapper written in Swift. If you don't want to export Kotlin declarations to Objective-C and Swift, use special hides a Kotlin declaration from Objective-C and Swift. See Kotlin Multiplatform Mobile Sample for an example. Kotlin modules can be used in Swift/Objective-C code if compiled into a framework ( see here for how to declare binaries). A Swift library can be used in Kotlin code if its API is exported to Objective-C with Pure Swift modules are not yet supported. See compilation configurations for more details. Objective-C frameworks and libraries can be used in Kotlin code if properly imported to the build (system frameworks are imported by default). Kotlin/Native provides bidirectional interoperability with Objective-C. This document covers some details of Kotlin/Native interoperability with Swift/Objective-C. ![]()
0 Comments
Leave a Reply. |