gpt4 book ai didi

ios - (Swift 2) 如何在我的数据库中获取一个随机的 Realm 对象?

转载 作者:行者123 更新时间:2023-11-28 08:40:25 24 4
gpt4 key购买 nike

我只是想知道是否有办法在 swift 2 中从我的 Realm 数据库中获取随机 Realm 条目这样做的原因是我想获得某个类别中的随机 Realm 对象。提前致谢

最佳答案

您可以使用随机索引来检索对象。像下面这样。

let dogs = realm.objects(Dog)
let randomDog = dogs[Int(arc4random_uniform(UInt32(dogs.count) - 1))]

关于ios - (Swift 2) 如何在我的数据库中获取一个随机的 Realm 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36658856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com