Kotlin & Swift Newbie Question

Hi!

last night I was reading about the Kotlin and Swift language and wondered what corresponds to a Xojo Module in Kotlin/Swift?

Interfaces and classes seem to work analogously. Am I right about this? And how about the other structures?

Xojo         Swift                Kotlin
————         —————                ——————
Class        class                class
Interface    protocol             interface
Module       single Swift files   ?

Sub          func                 fun
Function     func                 fun
Structure    struct               ?
Delegate     delegate             ?

If something like Modules are possible in both language, are the also able to create nested modules? If yes, how?

Swift doesn’t have a direct concept of “Module”… what I do is group like “methods” [func] in their own .SWIFT file

A Swift Structure is struct
and where applicable Delegate is delegate, although if you are creating your own classes, you can name it whatever you want
Also don’t be fooled by the simplictiy of Xojo in relation to struct and enum, those in Swift are 1000x more powerful

Swift also allows nesting… you obviously can have func within a class, you can also nest “private” func within other func

func outter() {
     func inner() -> Int {
         return 3
     }
    let x = inner()
}
1 Like

Thanks David. So the concept of nested Modules with various scopes doesn’t exist in Swift. Does that mean, all single Swift files will have public scope? How about shared properties/methods?

They have what ever scope you apply…
If you use the “xxx.swift” file as your “module”… then you can specify various classes and functions within that file as “fileprivate” … a level of scope that doesn’t exist in Xojo… Anything marked “fileprivate” is only available to other code in that same file.

1 Like

It seems so wrong to call a method or function fun

1 Like

saves those whole 5 characters

and surely you know that the speed with which you write code has EVERYTHING to do with its quality ?? :stuck_out_tongue: