【发布时间】:2020-09-05 01:15:01
【问题描述】:
为什么不管索引 0 处的对象是否在集合中,这句话总是正确的?
smallestNumberSort 是一个 NSMutableArray
smallestNumberSet 是一个 NSSet
if ([smallestNumberSet containsObject:[NSSet setWithObject:[smallestSortComplete objectAtIndex:0]]] == NO)
[outcome removeAllObjects];
最小代码示例
-(void)GoodCoordinates
{
NSCountedSet *outcome = [[NSCountedSet alloc] init]; //will contain 4 random plot point between -50 and +50
NSMutableArray smallestSortComplete = [NSMutableArray alloc] init];
NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
NSMutableArray smallestCoords = [NSMutableArray alloc] initwithObjects:
[NSNumber numberWithInt:1]
[NSNumber numberWithInt:7]
[NSNumber numberWithInt:-14]
[NSNumber numberWithInt:10]
[NSNumber numberWithInt:-21],nil];
BOOL (inBounds = NO)
{
[smallestSortComplete removeAllObjects];
smallestSortComplete = [NSMutableArray arrayWithArray:[outcome allObjects]];
[smallestSortComplete sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
if ([smallestCoords containsObject:[smallestSortComplete objectAtIndex:0]] == NO)
[outcome removeAllObjects];
else
inBounds = YES;
}
【问题讨论】:
-
请发布minimal reproducible example,其中
[smallestSortComplete objectAtIndex:0]在smallestCoords中。
标签: xcode comparison nsset