Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 869 Bytes

Extension functions over platform class.md

File metadata and controls

30 lines (20 loc) · 869 Bytes

Extension functions over platform class

A wrapper class appears with a function that accepts an object of the desired class.

Explanations

A platform class is, for example, some primitive type, or a class specific to a particular platform (Bundle for Android, UILabel for iOS, etc.).

In Kotlin, there is no difference in using an extension over a regular or platform class:

//ExtensionFunctionOverPlatformClass.kt

fun String.extensionFunctionOverStringClass() {
    println(this) //Do something
}

fun extensionFunctionOverPlatformClassExample() {
    "123".extensionFunctionOverStringClass()
}

After moving to Swift, the difference manifests itself in the appearance of a wrapper class for calling a function:

ExtensionFunctionOverPlatformClassKt.extensionFunctionOverStringClass("123")

Table of contents