File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -677,14 +677,21 @@ fun test() {
677677## Casting between mapped types
678678
679679When 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
683687val nsArray = listOf (1 , 2 , 3 ) as NSArray
688+ val nsString = " Hello" as NSString
684689val 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
You can’t perform that action at this time.
0 commit comments