Convert a Set to a Realm MutableSet

Viewed 94

I am sure there is a really simple way to do this but just stumped. Trying to take a string list of comma separated values and put into a Realm MutableSet. Have used the approach below but doesn't seem very elegant. eg "name1, name2, name3". Thanks.

let stringOfNames = nextBeing.alternateNames.lowercased()
let namesList = Set(stringOfNames.components(separatedBy: ","))
let namesMSet = MutableSet<String>()
for nextName in namesList {
    namesMSet.insert(nextName)
}
1 Answers

The .insert and can a single object or a series of objects so how about

let namesList = Set(stringOfNames.components(separatedBy: ","))
var mySet = MutableSet<String>()
mySet.insert(objectsIn: namesList)
Related