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
Core Data: Fetch all entities
提问by xhan
I want to know is there an equivalent to the MySQL SELECT * FROM table ORDER BY sth
to fetch all the results.
我想知道是否有等效于 MySQLSELECT * FROM table ORDER BY sth
来获取所有结果。
回答by Barry Wark
Use an NSFetchRequest
with a nil
predicate and an appropriate NSSortDescriptor
. On iOS, you should be using an NSFetchedResults
controller 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 NSFetchRequest
with the appropriate filters, sorts, etc. that you need.
通常,您希望NSFetchRequest
使用您需要的适当过滤器、排序等来设置。
-- Frank
——弗兰克