Ordered Sets and Core Data (NSOrderedSet)

后端 未结 3 1860
灰色年华
灰色年华 2021-02-05 23:54

I have a list of share prices with the properties dateTime and value.

Currently I am sorting the share prices when fetching them using a sort

相关标签:
3条回答
  • 2021-02-06 00:35

    I'm not sure how using an NSMutableOrderedSet would affect the underlying sqlite database. It is nice to think that it would store it in the order of the set, but the underlying implementation is a blackbox and I don't think there's any guarantee that it would work consistently, if it worked at all.

    If it's a performance gain you are looking for, I would think adding an index to that attribute would be the best approach.

    0 讨论(0)
  • 2021-02-06 00:46

    Ordered property on CoreData

    Mark the Ordered checkbox of your property in your CoreData model.

    Also be sure to set the CoreData automatic migration in your AppDelegate (options dictionary when creating PersistentStore). This way CoreData will be able to make this change without data lost.

    0 讨论(0)
  • 2021-02-06 00:50

    i would like to add to the accepted answer, if you have a NSSet, it must be changed to a NSOrderedSet after selecting the ordered checkbox

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