Jeremias Nunez
11/19/2020, 2:16 PMPrecondition failed: NSArray element failed to match the Swift Array Element type
Expected Movie but found SharedMovie: file Swift/ArrayBuffer.swift, line 354
My Movie class is defined like this:
@Serializable
data class Movie(
val name: String,
val tone: String,
val light: String,
val url: String,
val order: Int,
val version: Int
)
I found this issue but it doesn't provide any possible solution: https://github.com/JetBrains/kotlin-native/issues/2830sealed class ServiceResponse<out T> {
class Success<out T>(val data: T) : ServiceResponse<T>()
data class Error(val exception: Throwable,
val code: Int? = null,
val error: Boolean? = null,
val errors: List<GenericError>? = null,
val message: String? = null,
val method: String? = null,
val path: String? = null) : ServiceResponse<Nothing>()
}
Where T was a List<Movie>. The generated Obj-C interface for this becomes ServiceResponse<NSArray>, so when casting between NSArray -> Swift Array, the name difference always caused the cast to fail. What I did was change T to be a class MoviesResponse which has a property that is a list of Movie. In that case the generated Obj-C interface becomes ServiceResponse<MoviesResponse> and accessing the array directly causes no problems