2013-04-14 71 views
0

我一直在嘗試使用NSSet和NSMutable集來比較使用IntersectSet函數的一組數字。但是,我相信我會用整數來反對類型。有沒有辦法創建一個NSSet並使用IntersectsSet函數來整數。還有另外一種方法來完成這一切嗎?比較數字集

下面的代碼片段:

NSSmutableArray *compareRow [[NSMutableArray alloc] init]; 
NSSet *A_Table = [[NSSet alloc] initWithObjects:@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12",nil]; 

//... 
//Reading some data from a file. 

     //Populate the tables with the third arrays 
     [currentHistoryRow addObject:[NSNumber numberWithInt:post1]]; 
     [currentHistoryRow addObject:[NSNumber numberWithInt:post2]]; 
     [currentHistoryRow addObject:[NSNumber numberWithInt:post3]]; 
     [currentHistoryRow addObject:[NSNumber numberWithInt:post4]]; 
     [currentHistoryRow addObject:[NSNumber numberWithInt:post5]]; 


     NSSet *compareRow = [[NSSet alloc] initWithArray:currentHistoryRow]; 

     if ([compareRow intersectsSet:A_Table]) { 
      // You'll see this message 
      NSLog(@"subset present"); 
     } 

我想A_Table和compareRow是同一類型的不是那麼的條件是不正確的。

+1

發表一些代碼。 –

回答

1

將整數包裝在NSNumber中,然後將它們添加到NSSet。交叉路口將按照廣告方式工作。

NSSet *set = [NSSet setWithObjects: @10, @20, nil]; 
// etc.