抱歉,我之前没有正确理解您的问题。也许您可以尝试以下方法:
NSMutableArray *points1 = [NSMutableArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(1, 1)],
[NSValue valueWithCGPoint:CGPointMake(1, 1)],
[NSValue valueWithCGPoint:CGPointMake(1, 2)],
[NSValue valueWithCGPoint:CGPointMake(1, 3)], nil];
NSArray *points2 = [NSArray arrayWithObject:
[NSValue valueWithCGPoint:CGPointMake(1, 1)]];
NSInteger index = NSNotFound;
for (NSValue *point in points2) {
index = [points1 indexOfObject:point];
if (NSNotFound != index) {
[points1 removeObjectAtIndex:index];
}
}
NSLog(@"%@", points1);
=> 2012-03-04 00:02:26.376 foobar[19053:f803] (
"NSPoint: {1, 1}",
"NSPoint: {1, 2}",
"NSPoint: {1, 3}"
)
更新
NSNotFound 在NSObjCRuntime.h 中定义。你可以通过命令 + 点击 Xcode 中的符号 NSNotFound 来找到它。
定义是
enum {NSNotFound = NSIntegerMax};
我知道使用它的原因是查看 NSArray 文档中的 indexOfObject: 方法,内容如下:
返回值
对应数组值等于 anObject 的最低索引。如果数组中没有一个对象等于anObject,则返回NSNotFound。