編譯器是一個機器人,它會標記你代碼中被 Clang 規則定義為錯誤的地方。但是,你總是比 Clang 更聰明。通常,你會發現一些討厭的代碼 會導致這個問題,而且不論怎么做,你都解決不了。你可以這樣明確一個錯誤:
~~~
- (NSInteger)divide:(NSInteger)dividend by:(NSInteger)divisor
{
#error Whoa, buddy, you need to check for zero here!
return (dividend / divisor);
}
~~~
類似的,你可以這樣標明一個 警告
~~~
- (float)divide:(float)dividend by:(float)divisor
{
#warning Dude, don't compare floating point numbers like this!
if (divisor != 0.0) {
return (dividend / divisor);
}
else {
return NAN;
}
}
~~~