Kotlin Multiplatform things to be aware for iOS Developer

Kotlin Multiplatform is a new tool that allows you to write applications that run on multiple platforms, including Android and iOS. It works with any existing Java libraries and Kotlin libraries, so it should be a great way to expand your reach as an app developer.

Know your data types

You need to understand the data types in Kotlin and Swift. While these languages are similar, they don't have the same data types. In Kotlin, you need to be careful of your variable types when working with Swift.

In Objective-C, there are three basic categories of data types: scalar (boolean), string and number (integer or floating point). In addition to those three standard classes there is a range of other primitive wrapper classes such as NSString and NSArray which correspond to basic C#/Java classes like string and array respectively.

Kotlin has no nullability but does have value type vs reference type semantics where reference types behave like in Java or C# while value types behave like those in C++ or Swift .

Pay extra attention to nullability

The next thing to be aware of is the nullability of your code. Kotlin is null-safe by default, but Swift isn’t. In Kotlin, you can mark a variable as non-nullable with the @NonNull annotation:

// Kotlin

@NonNull var x: Int = 5 // Cannot assign a null here

// Swift

var x: Int ! = 5 // Cannot assign a null here

Understand the differences in non-nullability

Kotlin uses the keyword "nullable" to denote a type that can be null. Swift uses the keyword "optional" for this purpose.

In Kotlin, every type is non-nullable by default and you need to explicitly declare it as such if you want it to be possible to have null values of that type. In Swift, all types are optional by default and you need to explicitly make them non-optional if you don't want them to hold null values.

All Objects get refactored to Any

Kotlin Multiplatform is a compiler feature that can help you write code for both platforms (Android and iOS) with a single codebase. This means that you can use Kotlin in your next app, no matter what platform it’s intended to run on. However, this also means that all objects get refactored to Any when they are passed around or stored in an array or map.

Generic parameters have limitations

  • You can use generic parameters in classes, interfaces, and other types.
  • You cannot declare generic methods or properties with generic parameters.
  • You can declare type aliases with generic parameters as long as they are not directly referenced in the code (i.e., a type alias cannot be used as an argument to a function)

You can use Kotlin Multiplatform for iOS, but you have to be careful.

In general, you can use Kotlin Multiplatform for iOS, but you have to be careful. You need to know your data types and pay extra attention to nullability. If you are doing any integration with native code, you also have to understand the differences in non-nullability between Swift and Kotlin.

Conclusion

In conclusion, we recommend that you should be careful when using Kotlin Multiplatform for iOS. This can be a great tool for your app but it does have limitations and there are things to keep in mind so that you do not run into any issues down the road.