Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does apple use NSOrderedSet instead of NSArray for ordered mutli value relationship in CoreData?

In core data if we have multi value relationship, such as when a business can have several keywords, in the subclass NSManagedObject generator, Apple will use NSOrderedSet instead of NSArray.

They are both almost equal except that checking ownership is slightly faster in NSOrderedSet.

Any reason why Apple doesn't use the far more familiar and famous NSArray?

like image 724
Anonymous White Avatar asked Oct 23 '12 13:10

Anonymous White


2 Answers

My guess would be: Because NSOrderedSet manages a collection of distinct elements, similar to NSSet for unordered relationships.

With NSArray you could create an object which is related to another object more than once.

like image 148
Martin R Avatar answered Oct 21 '22 11:10

Martin R


From the docs:

You can use ordered sets as an alternative to arrays when the order of elements is important and performance in testing whether an object is contained in the set is a consideration— testing for membership of an array is slower than testing for membership of a set.

like image 37
Rob Napier Avatar answered Oct 21 '22 13:10

Rob Napier