Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:28:44+00:00 2026-06-08T06:28:44+00:00

I have a pretty simple little schema that looks like this: Trail –> Segment

  • 0

I have a pretty simple little schema that looks like this:

Trail –> Segment –> Coordinate

All of the proper relationships are in place to make this work, and they certainly let me do something like this:

NSArray *trails = <query all trails>

for (Trail *trail in trails) {
    for (Segment *segment in trail.segments) {
        for (Coordinate *coordinate in segment.coordinates) {
            //do something with coords
        }
    }
}

Coming from a Django background, I was delighted with this, and assumed the fewest possible queries would be run against sqlite3. Wrong! There is a query made for each and every object in these loops.

I’ve now read the Core Data documentation on faulting, I understand what’s going on, although I would really like to know what the best practices are for dealing with a situation like this. I need every single object in memory (the coords model has ~100,000 objects) because they are all used at one moment to plot a trail on a map.

How should I deal with this ultra lazy loading?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:28:46+00:00Added an answer on June 8, 2026 at 6:28 am

    You could use the setRelationshipKeyPathsForPrefetching: method of NSFetchRequest for this. From the documentation:

    Prefetching allows Core Data to obtain related objects in a single
    fetch (per entity), rather than incurring subsequent access to the
    store for each individual record as their faults are tripped.

    So in your initial fetch request for the trails you could add

    [request setRelationshipKeyPathsForPrefetching:
        [NSArray arrayWithObjects:@"segments", @"segments.coordinates", nil]]
    

    (I never tried this with 2 levels deep, only with one level.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty simple ASP.NET Web Form that looks a bit like the
I have this pretty simple jquery example: http://jsfiddle.net/clifgray/NTd95/1/ and in that jsfiddle it works
I have pretty simple jquery code : $(document).ready(function(){ $('img.marqFl').on({ mouseenter: function() { $(this).animate({height: 300},
I have a pretty simple problem. Basically I have an array called $list that
Hopefully this is a pretty simple question for someone to answer. I have a
I have a row of evenly-spaced navigation items, which looks like this: The currently
I have a simple little osx app that just starts up an IKPictureTaker and
I have written a pretty simple Windows service in C# that starts up automatically
This is a very simple form that I have found on the web (as
I feel like this is probably a pretty simple question, but this is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.