1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Swift】Realm Listのシャッフル

Last updated at Posted at 2020-05-18

他は知らないがSwiftのRealmはshuffleがサポートされていない。

自分でシャッフルする。
それだけの記事。

func shuffle() {
    for _ in array {
        let swap1 = Int.random(in: 0..<array.count)
        let swap2 = Int.random(in: 0..<array.count)
        try! realm.write {
            list.swapAt(swap1, swap2)
        }
    }
}

まぁswapする回数はお好み。

どうやってシャッフルすればいいか結局小一時間悩んだ。
クソ時間な無駄ですね!!!

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?