我只是花了一些时间找出为什么一个可变集合没有正确地与另一个集合相交,使用
[someMutableSet intersectsSet:anotherSet]; // not the best idea
当然,正确的语法是[someMutableSet intersectSet:anotherSet]
和上面一行的意思不同——它是一个返回值BOOL
类型的方法调用。
由于我-Wall -Wextra
启用了选项,因此应该将其视为警告。但它没有被抓住。我通过尝试进一步调查,哪里types
是NSMutableSet
:
(void)[types intersectsSet:types]; // -> no warning, this is expected
(BOOL)[types intersectsSet:types]; // (1) -> warning, this is expected
而且,再次,如果我这样做:
[types intersectsSet:types]; // (2) -> no warning, UNEXPECTED
没有警告,即使该方法被定义为- (BOOL)intersectsSet:(NSSet *)otherSet;
人们期望 (1) 和 (2) 是等价的。也许恶意编译工具认为(1)与(2)相比具有更危险的性质,但我问为什么这会影响警告?
那么,如何使编译器在 (2) 中产生与 (1) 中相同的警告?