Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 2.0 one-to-many relationship - still NSOrderedSet?

In Swift 2.0, are one-to-many relationships in Core Data still NSOrderedSets?

I cannot seem to be able to cast/downcast appropriately to ever not throw errors.

Does anyone have a simple example of this in Swift 2.0?

like image 682
Kent Avatar asked Aug 21 '15 01:08

Kent


Video Answer


1 Answers

Only if you flag the relationship with the option "Ordered". If not, then it's a NSSet.

I don't agree with the accepted answer because in Swift 2.0 bridging from NSSet to a Set happens automatically, so if you can subclass the CoreData entity, you can just write:

@NSManaged var oneToManyOfTypeFoo: Set<Foo>

And then adding and removing elements becomes trivial, because you can just use the insert and remove methods from Set.

like image 65
FranMowinckel Avatar answered Oct 17 '22 01:10

FranMowinckel