-1

Is there a way to convert NSMutableSet to NSSet? I have tried several methods: moving to an NSArray and the setWithArray; instantiating an NSSet with the contents of the NSMutableSet. The program compiles but I get a run time error.

 NSMutableArray  *temp = [[NSMutableArray alloc] init];
 NSMutableSet    *num1 = [[NSMutableSet alloc] init];
 NSArray         *num2 = [[NSArray alloc] init];
 NSSet           *num3 = [[NSSet alloc] init];

 num1 = [checkset mutableCopy];  //checkset is of type NSSet
 num2 = [NSArray arrayWithArray:NoShows];
 num3 = [NSSet setWithArray:num2];

 [num1 minusSet:num3];
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Kevin McFadden
  • 337
  • 1
  • 5
  • 23

2 Answers2

4

copy of NSMutableSet returns a NSSet

In your sample:

NSSet *immutableSet = [checksetM copy]; // returns immutable copy
Yugal Jindle
  • 44,057
  • 43
  • 129
  • 197
0
-(NSSet *)ContainsNoShow:(NSMutableArray *)checkset
{

  NSSet *newcheckset = [[NSSet alloc] init];
  newcheckset = [NSSet setWithArray:NoShows];

  NSMutableSet *checksetM     = [NSMutableSet setWithArray:checkset];

  [checksetM minusSet: newcheckset];

  return checksetM;

}

Kevin McFadden
  • 337
  • 1
  • 5
  • 23