Skip to content

Commit 2d4bc08

Browse files
authored
fix: casting warning suppression (#5142)
1 parent 38103ef commit 2d4bc08

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

docs/topics/native/native-objc-interop.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,21 @@ fun test() {
677677
## Casting between mapped types
678678

679679
When writing Kotlin code, an object may need to be converted from a Kotlin type to the equivalent Swift/Objective-C type
680-
(or vice versa). In this case, a plain old Kotlin cast can be used, for example:
680+
or vice versa. In this case, you can use the [`as` cast](typecasts.md#unsafe-cast-operator), for example:
681681

682682
```kotlin
683+
@file:Suppress("CAST_NEVER_SUCCEEDS")
684+
import platform.Foundation.*
685+
686+
val nsNumber = 42 as NSNumber
683687
val nsArray = listOf(1, 2, 3) as NSArray
688+
val nsString = "Hello" as NSString
684689
val string = nsString as String
685-
val nsNumber = 42 as NSNumber
686690
```
687691

692+
IDEs might incorrectly emit "This cast can never succeed" warnings.
693+
In such cases, use the `@Suppress("CAST_NEVER_SUCCEEDS")` annotation.
694+
688695
## Subclassing
689696

690697
### Subclassing Kotlin classes and interfaces from Swift/Objective-C

0 commit comments

Comments
 (0)