我最近調試了一個問題,這個問題是由於枚舉與非枚舉值進行比較而導致的。這裏是一個簡化的例子:我可以啓用警告來比較枚舉值和非枚舉值嗎?
typedef NS_ENUM(NSInteger, MyType) {
TypeVal1,
};
...
MyType type = TypeVal1;
int randomValue = 0;
BOOL compareTypeAndPrimiative = (randomValue == typeA); // No warning
是否可以打開此警告?
如果如果需要通過明確鑄造我可以抑制:
BOOL iKnowWhatImDoing = (randomValue == (int) typeA);
很好的抓住了面具! – Sulthan