Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSSet to Swift Array

In CoreData I have defined an unordered to-many relationship. This relationship is defined in Swift like this:

@NSManaged var types : NSMutableSet 

However, to use Swift at it's best, I want to use a normal Swift array like Type[]. However, CoreData forces me to use NS(Mutable)Set. How can I type-cast / convert the NSSet to Array<Type>[]?

like image 423
Bouke Avatar asked Jun 26 '14 05:06

Bouke


People also ask

What is NSSet in Swift?

NSSet declares the programmatic interface for static sets of distinct objects. You establish a static set's entries when it's created, and can't modify the entries after that. NSMutableSet , on the other hand, declares a programmatic interface for dynamic sets of distinct objects.


1 Answers

var set = NSSet() //NSSet var arr = set.allObjects //Swift Array var nsarr = set.allObjects as NSArray  //NSArray 
like image 56
Connor Avatar answered Sep 20 '22 13:09

Connor