2017-01-26 1 views
0

NSMutableSetをNSSetに変換する方法はありますか?私はいくつかの方法を試した:NSArrayとsetWithArrayに移動する。 NSMutableSetの内容でNSSetをインスタンス化します。プログラムはコンパイルされますが、実行時エラーが発生します。 NSMutableSetNSMutableSetを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]; 

答えて

1

copyあなたのサンプルではNSSet

を返します。

NSSet *immutableSet = [checksetM copy]; // returns immutable copy 
0
-(NSSet *)ContainsNoShow:(NSMutableArray *)checkset 
{ 

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

    NSMutableSet *checksetM  = [NSMutableSet setWithArray:checkset]; 

    [checksetM minusSet: newcheckset]; 

    return checksetM; 

}

関連する問題