I'm not sure if I just did not found any information or if it's not possible.
I've looked up several pages. I want to use generic a generic version of the NSOrderedSet in Swift.
With a Set you can do this:
Swift’s Set type is bridged to Foundation’s NSSet class. Source: Apple Docs - Sets
@property NSArray<NSDate *> *dates;
@property NSSet<NSString *> *words;
@property NSDictionary<NSURL *, NSData *> *cachedData;
var dates: [NSDate]
var words: Set<String>
var cachedData: [NSURL: NSData]
No, there is no ordered set in Swift and in all honesty, you shouldn't be using an ordered set period. They are very rarely of use.
But some times, its useful. So you don't have to sort your data by yourself. Especially when you have an entity with a list of sub entities they won't be sorted because it is a set. And then you would have to create a array to have the data prepared in a specific order because a plain set doesn't keep its order. So for core data it is useful especially in use with the NSFetchedResultsController.
It is a lazy addition to Core Data that never should have happened. It is never more useful or more performant than writing your own sort routine. Writing a convenience method in the subclasses to produce an ordered array will be faster and more performant than using an
When you are using an
NSFetchedResultsController it is completely useless since the
NSFetchedResultsController orders everything for you.