I have a Core data model with a 32bit hash value. I need to look up specific hash values quickly. Should I use the indexed property? I have no idea what it does and the documentation is no help (am I looking in the wrong place?)
So what does indexed do exactly?
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.
Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.
Even though Core Data knows how to use a SQLite database as its persistent store, that doesn't mean you can hand it any SQLite database. The database schema of the SQLite database used by Core Data is an implementation detail of the framework. It isn't publicly documented and liable to change.
Fetch Index Elements are part of Apple's new indexing API, announced at WWDC 2017. They allow you to specify one or more Index Elements; properties that are used to create an index for faster database searches.
I would recommend to read this on indexes: http://en.wikipedia.org/wiki/Index_(database).
Simply put, a database engine creates a new structure which keeps the indexed column (which corresponds to a property) sorted and a link to the corresponding row for each entry (primary key). This allows for faster searches (since search in ordered lists is faster than in unordered lists). But this increases used storage (for the data structure), and insertion times (to keep the structure sorted).
So yes, you should use indexes in such cases.
If you check the box, Core Data will build an index of the values, which will make searching faster and more efficient. It's like what Spotlight uses. Without the index it'll have to travel through the database every time. You say you need to look up the values quickly—then you should index them.
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