Maybe this question is answered in the official doc, but I'm not seeing it...
In Swift we are used to write something like
class Jazz {
...
}
extension Jazz {
func swing() {
...
}
}
and place that whole code snippet in a single file, say Jazz.swift
.
We don't seem to be able to do the corresponding thing in Kotlin? I'm always finding my selfe writing e.g. one Jazz.kt
and one JazzExtensions.kt
, which simply isn't always the clearest way of structuring the code.
Any input on this is appreciated.
You can place the extension function inside or outside the class:
Outside:
Inside (in the
companion object
):