You can use fast code in Codename. One native code instead of Objective-C.

I need to insert my own code into my Codename One app. I am completely new to iOS programming, so I need to learn Objective-C. However, I read that Swift was the successor to Objective-C, and I would feel more comfortable with the Swift syntax. But I do not know if Swift is supported in Codename One. If you look at the iOS source code created by Codename One, although I'm not 100% sure, it looks like C code (I could be wrong).

On her blog, Shanna (from Codename One) wrote that

Codename He will compile everything down to plain old C code, so we won’t be much affected by this change - at least there were some native parts that use Objective-C that need updating. Fortunately, if you are a Codename One user, you do not need to worry about these details because you are working in Java.

I don’t understand why I am asking if it is possible to use Swift code in Codename One code?

Thanks so much for helping clarify this topic!

Greetings

+7
ios swift codenameone native-code
source share
1 answer

Yes and no. You can probably compile Swift code into a static library today (.a file) and just use it like any static lib, where Objective-C code just acts like a bridge.

Using Swift directly is problematic due to several factors:

  • Currently we are still using an outdated version of xcode when creating, we tried to upgrade to the latest version , but had setback . We will be looking forward to migrating before 3.5, if not soon after.
    Swift requires a relatively new version of xcode, so until we make sure that implementing Swift code is problematic.

  • Swift assumes ARC. This is what we tried to integrate with the GC, but currently it does not work very well.

  • We need to generate Swift stubs as an option, this is problematic, since you have an existing cn1lib or a native interface that relies on Objective-C, it can create a conflict.

But let's get back a little. Swift is a huge advantage over Objective-C, which is pretty old. But Codename One developers have no significant advantages ...

  • It's not as fast as Codename One translates to C, which is faster than Swift and Objective-C

  • This will not make the code cleaner, if you have a lot of code in your own interfaces, then you are doing something wrong. Most of your code in Java anyway, you can discuss the virtues of Java and Swift, but if you use Codename One, then you pretty much chose Java.

  • If you need to use an application written in Swift, you can pack it as a static library.

Thus, there is currently no real use case for Swift in Codename One.

+1
source share

All Articles