Core Data to-many relationships. Are they Lazy Load?

后端 未结 1 1005
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-03 13:59

I have the typical model in Core Data (for iPhone) with Departments and Employesss (Department ->> Employee).

I dont want to load all employees of a department each time

1条回答
  •  囚心锁ツ
    2021-02-03 14:48

    No, objects related to to-many and to-one relationships are loaded lazily by default. However, If you need to access many of them each time you fetch a Department, then for performance reasons you may ask Core Data to load them simultaneously (this is called pre-fetching). You can do this as follow:

    [fetchRequest setReturnsObjectsAsFaults:NO];
    [fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"employees", nil]];
    

    0 讨论(0)
提交回复
热议问题