IOS CORE DATA GUIDE

🔍 Core Data Fetch Index for faster searches

Rajai Kumar
Nerd For Tech
Published in
2 min readJan 29, 2023

--

When you are working with CoreData, you should use all the tools from it’s arsenal to make it perform at its best. One such tool is this fetch index. Setting fetch index improves the filtering speed by a significant level.

Credits: iloveimg.com

🏃🏼‍♂️ Let’s jump to the steps:

  1. First, go to your Core Data model and select the entity you want to work with.
  2. Now press and hold the Add Entity button and a view will appear with some items.
  3. Select Add Fetch Index from that view.
  4. Now a child node will appear under the selected entity with the name “byPropertyIndex”.
  5. Rename it appropriately. In my case, I have renamed it to “byBookNameIndex” because that is what I am going to do.
  6. Now select the child node and a new page will appear in the right.
  7. Press the + button under the property and create a new fetch index element.
  8. Now change the the property to the one which you want to index, in my case it’s “bookName”.

Note: Do it only to the needed property. If you feel some query is running slow or if you think it may become slow then do this.

📺 GIF & YouTube for your reference.

🙏 Thanks hackingwithswift

📰 My other articles related to Core Data

  1. Core Data Fetch Batch Insertion
  2. Core Data Fetch Request template

--

--

Rajai Kumar
Nerd For Tech

I’m a workaholic iOS developer. I focus a lot on UX and product efficiancy.