-1

有没有办法将 NSMutableSet 转换为 NSSet?我尝试了几种方法:移动到 NSArray 和 setWithArray;用 NSMutableSet 的内容实例化一个 NSSet。程序编译,但我得到一个运行时错误。

 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];
4

2 回答 2

4

copyofNSMutableSet返回一个 NSSet

在您的示例中:

NSSet *immutableSet = [checksetM copy]; // returns immutable copy
于 2017-03-06T22:11:37.980 回答
0
-(NSSet *)ContainsNoShow:(NSMutableArray *)checkset
{

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

  NSMutableSet *checksetM     = [NSMutableSet setWithArray:checkset];

  [checksetM minusSet: newcheckset];

  return checksetM;

}

于 2017-01-27T03:22:53.393 回答