I want to save my struct, so that the order of the items doesn´t get changed if the user closes the app. When he opens it again the order should continue, like he has never left.
Here is my code:
struct RandomItems
{
var items : [String]
var seen = 0
init(_ items:[String])
{ self.items = items }
mutating func next() -> String
{
let index = Int(arc4random_uniform(UInt32(items.count - seen)))
let item = items.remove(at:index)
items.append(item)
seen = (seen + 1) % items.count
return item
}
}
Aucun commentaire:
Enregistrer un commentaire