0

我一直在尝试使用 NSSet 和 NSMutable set 来使用 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 不是同一类型,因此条件永远不会成立。

4

1 回答 1

1

将整数包装进去NSNumber,然后将它们添加到NSSet. 十字路口将按广告宣传。

NSSet *set = [NSSet setWithObjects: @10, @20, nil];
// etc.
于 2013-04-14T04:27:55.187 回答