Andrew Paul Simmons
Andrew Paul Simmons

Reputation: 4523

IOS - Convert from NSSet to NSMutableSet

Given an NSSet what is the best way to get an NSMutableSet with those same objects?

To be clear if you have an instance of NSSet what would be the most performant and simple way to get an NSMutable set with those same objects?

Upvotes: -5

Views: 932

Answers (1)

trungduc
trungduc

Reputation: 12154

There are 2 ways to achieve it.

  • Use mutableCopy

    Objective-C

    NSMutableSet* mutableSet2 = [YOUR_SET mutableCopy];
    

    Swift

    let mutableSet = YOUR_SET.mutableCopy()
    
  • Use setWithSet:

    Objective-C

    NSMutableSet* mutableSet = [NSMutableSet setWithSet:YOUR_SET];
    

    Swift

    let mutableSet = NSMutableSet.init(set: YOUR_SET)
    

Upvotes: 3

Related Questions