macos 核心数据:获取所有实体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4638915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:34:31  来源:igfitidea点击:

Core Data: Fetch all entities

iphoneobjective-cmacoscore-data

提问by xhan

I want to know is there an equivalent to the MySQL SELECT * FROM table ORDER BY sthto fetch all the results.

我想知道是否有等效于 MySQLSELECT * FROM table ORDER BY sth来获取所有结果。

回答by Barry Wark

Use an NSFetchRequestwith a nilpredicate and an appropriate NSSortDescriptor. On iOS, you should be using an NSFetchedResultscontroller as the query may return more items that you want in memory at once.

使用NSFetchRequest带有nil谓词和适当的NSSortDescriptor. 在 iOS 上,您应该使用NSFetchedResults控制器,因为查询可能会一次返回更多您想要在内存中的项目。

回答by Frank C.

Xhan,

赞,

The 'grammar' may be equivalent but there is some work you have to do in the application. A good starting explanation is Here.

“语法”可能是等价的,但您必须在应用程序中做一些工作。一个很好的开始解释是Here

In general you'd want to setup a NSFetchRequestwith the appropriate filters, sorts, etc. that you need.

通常,您希望NSFetchRequest使用您需要的适当过滤器、排序等来设置。

-- Frank

——弗兰克