Convert Swift Int64? to Kotlin KotlinLong?
In KMM shared module, if the parameter is Long?, then in swift, the parameter type will be KotlinLong?, in swift code, I use the Int64? as…
In KMM shared module, if the parameter is Long?
, then in swift, the parameter type will be KotlinLong?
, in swift code, I use the Int64?
as the parameter type, when when call kmm
method, we need to convert Int64?
to KotlinLong?
, I used to check the parameter is nil or not, if not, then create a KotlinLong
Object.
Today, I find it’s easier to write an extension on Int64 type as following.
extension Int64 {
func toKotlinLong() -> KotlinLong {
return KotlinLong(value: self)
}
}
After define an extension method toKotlinLong
, then we can just use param?.toKotlinLong()
to convert Int64?
to KotlinLong?
.