Hi there! I have a problem with converting Realm type List< Int > array to Int array [Int] when writing jsonData to Realm.
struct Movies: Codable {
let genreIDs: [Int]?
}
class CachedMovies: Object {
let genreIDs: List<Int>?
func saveMovies(movies:[Movies]) { do { let realm = try! Realm() try realm.write { movies.forEach { (movie) in let movieRealm = CachedMovies() movieRealm.id = movie.id ?? 0 movieRealm.genreIDs = movie.genreIDs ?? [] // here's error: Cannot assign value of type '[Int]?' to type 'List<Int>?' } } }
I tried to change List type to Results and convert Results to Int by using this extension but it's not work.
extension Results {
func toArray<T>(type: T.Type) -> [T] {
return compactMap { $0 as ? T }
}
}
Could you please help me how can I assign arrays correctly?