I want to know is there an equivalent to the MySQL SELECT * FROM table ORDER BY sth
to fetch all the results.
Fetch requests allow us to load Core Data results that match specific criteria we specify, and SwiftUI can bind those results directly to user interface elements. If you followed my Core Data and SwiftUI set up instructions, you've already injected your managed object context into the SwiftUI environment.
Fetching Data From CoreData We have created a function fetch() whose return type is array of College(Entity). For fetching the data we just write context. fetch and pass fetchRequest that will generate an exception so we handle it by writing try catch, so we fetched our all the data from CoreData.
A description of search criteria used to retrieve data from a persistent store.
In some respects, an NSManagedObject acts like a dictionary—it's a generic container object that provides efficient storage for the properties defined by its associated NSEntityDescription instance.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With