You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -32,27 +32,134 @@ Kotlin modules can be used in Swift/Objective-C code if compiled into a framewor
32
32
* See [Build final native binaries](multiplatform-build-native-binaries.md#declare-binaries) to see how to declare binaries.
33
33
* Check out the [Kotlin Multiplatform sample project](https://github.com/Kotlin/kmm-basic-sample) for an example.
34
34
35
-
### Hiding Kotlin declarations
35
+
### Hide Kotlin declarations from Objective-C and Swift
36
36
37
-
> `@HiddenFromObjC`and `@ShouldRefineInSwift` annotations are [Experimental](components-stability.md#stability-levels-explained) and require[opt-in](opt-in-requirements.md).
37
+
> The `@HiddenFromObjC`annotation is [Experimental](components-stability.md#stability-levels-explained) and requires[opt-in](opt-in-requirements.md).
38
38
>
39
39
{type="warning"}
40
40
41
-
If you don't want to export Kotlin declarations to Objective-C and Swift, use special annotations:
41
+
To make your Kotlin code more Objective-C/Swift-friendly, you can hide a Kotlin declaration from Objective-C and Swift
42
+
with `@HiddenFromObjC`. The annotation disables a function or property export to Objective-C.
42
43
43
-
*`@HiddenFromObjC` hides a Kotlin declaration from Objective-C and Swift. The annotation disables a function or property
44
-
export to Objective-C, making your Kotlin code more Objective-C/Swift-friendly.
44
+
Alternatively, you can mark Kotlin declarations with the` internal` modifier to restrict their visibility in the
45
+
compilation module. Choose `@HiddenFromObjC` if you only want to hide the Kotlin declaration from Objective-C and Swift,
46
+
but still keep it visible from other Kotlin modules.
45
47
46
-
[See an example in the Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/HiddenFromObjC.md).
47
-
*`@ShouldRefineInSwift` helps to replace a Kotlin declaration with a wrapper written in Swift. The annotation marks a
48
-
function or property as `swift_private` in the generated Objective-C API. Such declarations get the `__` prefix,
49
-
which makes them invisible from Swift.
48
+
[See an example in the Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/HiddenFromObjC.md).
50
49
51
-
You can still use these declarations in your Swift code to create a Swift-friendly API, but they won't be suggested in
52
-
the Xcode autocomplete.
50
+
### Use refining in Swift
53
51
54
-
* For more information on refining Objective-C declarations in Swift, see the [official Apple documentation](https://developer.apple.com/documentation/swift/improving-objective-c-api-declarations-for-swift).
55
-
* For an example on how to use the `@ShouldRefineInSwift` annotation, see the [Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/ShouldRefineInSwift.md).
52
+
> The `@ShouldRefineInSwift` annotation is [Experimental](components-stability.md#stability-levels-explained) and requires [opt-in](opt-in-requirements.md).
53
+
>
54
+
{type="warning"}
55
+
56
+
`@ShouldRefineInSwift` helps to replace a Kotlin declaration with a wrapper written in Swift. The annotation marks a
57
+
function or property as `swift_private` in the generated Objective-C API. Such declarations get the `__` prefix,
58
+
which makes them invisible from Swift.
59
+
60
+
You can still use these declarations in your Swift code to create a Swift-friendly API, but they won't be suggested in
61
+
the Xcode autocomplete.
62
+
63
+
* For more information on refining Objective-C declarations in Swift, see the [official Apple documentation](https://developer.apple.com/documentation/swift/improving-objective-c-api-declarations-for-swift).
64
+
* For an example on how to use the `@ShouldRefineInSwift` annotation, see the [Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/ShouldRefineInSwift.md).
65
+
66
+
### Change declaration names
67
+
68
+
> The `@ObjCName` annotation is [Experimental](components-stability.md#stability-levels-explained) and requires [opt-in](opt-in-requirements.md).
69
+
>
70
+
{type="warning"}
71
+
72
+
To avoid renaming Kotlin declarations, use the `@ObjCName` annotation. It instructs the Kotlin compiler to use the
73
+
custom Objective-C and Swift name for the annotated class, interface, or another Kotlin entity:
[See another example in the Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/ObjCName.md).
88
+
89
+
### Provide documentation with KDoc comments
90
+
91
+
Documentation is essential for understanding any API. Providing documentation for
92
+
the shared Kotlin API allows you to communicate with its users on matters of usage, dos and don'ts, and so on.
93
+
94
+
By default, [KDocs](kotlin-doc.md) comments are not translated into corresponding comments when generating
95
+
an Objective-C header. For example, the following Kotlin code with KDoc:
96
+
97
+
```kotlin
98
+
/**
99
+
* Prints the sum of the arguments.
100
+
* Properly handles the case when the sum doesn't fit in 32-bit integer.
101
+
*/
102
+
funprintSum(a:Int, b:Int) =println(a.toLong() + b)
103
+
```
104
+
105
+
Will produce an Objective-C declaration without any comments:
[See another example in the Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/overview/ObjCName.md).
126
-
127
211
### Initializers
128
212
129
213
A Swift/Objective-C initializer is imported to Kotlin as constructors or as factory methods named `create`.
@@ -190,7 +274,7 @@ Here's how the `kotlin.Any` functions are mapped to Swift/Objective-C:
190
274
[See an example with data classes in the Kotlin-Swift interopedia](https://github.com/kotlin-hands-on/kotlin-swift-interopedia/blob/main/docs/classesandinterfaces/Data%20classes.md).
191
275
192
276
You can specify a more idiomatic name in Swift or Objective-C, instead of renaming the Kotlin declaration with
193
-
the [`@ObjCName` annotation](#custom-declaration-names).
277
+
the [`@ObjCName` annotation](#change-declaration-names).
194
278
195
279
### Errors and exceptions
196
280
@@ -523,75 +607,6 @@ library. To disable these compiler checks, add the `disableDesignatedInitializer
523
607
See [Interoperability with C](native-c-interop.md) for an example case where the library uses some plain C features,
524
608
such as unsafe pointers, structs, and so on.
525
609
526
-
## Export of KDoc comments to generated Objective-C headers
527
-
528
-
> The ability to export KDoc comments to generated Objective-C headers is [Experimental](components-stability.md).
529
-
> It may be dropped or changed at any time.
530
-
> Opt-in is required (see the details below), and you should use it only for evaluation purposes.
531
-
> We would appreciate your feedback on it in [YouTrack](https://youtrack.jetbrains.com/issue/KT-38600).
532
-
>
533
-
{type="warning"}
534
-
535
-
By default, [KDocs](kotlin-doc.md) documentation comments are not translated into corresponding comments when generating
536
-
an Objective-C header. For example, the following Kotlin code with KDoc:
537
-
538
-
```kotlin
539
-
/**
540
-
* Prints the sum of the arguments.
541
-
* Properly handles the case when the sum doesn't fit in 32-bit integer.
542
-
*/
543
-
funprintSum(a:Int, b:Int) =println(a.toLong() + b)
544
-
```
545
-
546
-
Will produce an Objective-C declaration without any comments:
0 commit comments