Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Realm list of Strings to Array of Strings in Swift

Tags:

xcode

swift

realm

I'm just starting up with RealmSwift, and I'm trying to store an array of Strings in Realm. It doesn't work, so now I'm using List<String>() as an alternative. However, how do I convert these Realm Lists back to [String] again? And if I can't do that, are there any alternatives?

Thanks

like image 896
Luke B Avatar asked Dec 23 '22 22:12

Luke B


1 Answers

However, how do I convert these Realm Lists back to [String] again

You can simply cast List to Array, because List has Sequence Support:

let list = List<String>()
let array = Array(list)
like image 170
pacification Avatar answered Dec 29 '22 12:12

pacification