Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何根据给定的索引范围检索领域中的数据?_Swift_Realm - Fatal编程技术网

Swift 如何根据给定的索引范围检索领域中的数据?

Swift 如何根据给定的索引范围检索领域中的数据?,swift,realm,Swift,Realm,我想根据给定的索引范围检索领域数据库中的数据。我做了一些研究,您可以在java领域中执行类似的操作: realm.where(clazz).between("count",0,1000).findAll(); // Get the first 1000 data 但我还没有在swift领域找到类似的功能。下面是我的get all函数: func getDataBasedOnIndex() -> Results<DataModel> { let re

我想根据给定的索引范围检索领域数据库中的数据。我做了一些研究,您可以在java领域中执行类似的操作:

realm.where(clazz).between("count",0,1000).findAll(); // Get the first 1000 data
但我还没有在swift领域找到类似的功能。下面是我的get all函数:

func getDataBasedOnIndex() -> Results<DataModel> {
    let realm = try! Realm()
    let localData =  realm.objects(DataModel.self)
    let sortProperties = [
        SortDescriptor (keyPath: "time", ascending: false)
    ]
    return localData.sorted(by: sortProperties)
}
func getDataBasedOnIndex()->结果{
让realm=try!realm()
让localData=realm.objects(DataModel.self)
设sortProperties=[
SortDescriptor(键路径:“时间”,升序:false)
]
返回localData.sorted(按:sortProperties)
}

基于上述函数,我希望在检索数据时进行分页。例如,我有一个
UITableView
,其中填充了从我的领域数据库检索到的数据。当第一次加载页面时,我只想显示数据库中的10个数据,但是当用户滚动到表视图的底部时,数据会不断增加,直到用完为止。如何在领域中为swift执行相同的操作?

没有必要在领域查询中实现分页,因为它们在框中是“惰性”的。 这意味着只有在访问对象时才从查询中加载对象