2013-04-14 135 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.