Adds "Enums do not start with zero value" and "Switch statements are exhaustive" sections.

This commit is contained in:
Wojciech Nagrodzki 2015-06-12 16:58:14 +02:00
parent 0e5b6d5b26
commit cac1b0b524
Signed by: wnagrodzki
GPG key ID: E9D0EB0302264569
2 changed files with 36 additions and 1 deletions

Binary file not shown.

View file

@ -206,7 +206,7 @@ Please pay attention to the linespacing, it is also a rule.
typedef NS_ENUM(NSInteger, Enumeration) {
EnumerationA,
EnumerationA = 1,
EnumerationB
};
@ -477,6 +477,41 @@ Importing a header file is allowed:
In any other case a forward declaration should be applied.
\subsection{Enums do not start with zero value}
The rule guards against retrieving a proper enum value from nil object.
\begin{codelisting}
typedef NS_ENUM(NSUInteger, PaymentMethod) {
PaymentMethodCash = 1,
PaymentMethodCreditCard,
PaymentMethodCheque,
};
\end{codelisting}
\subsection{Switch statements are exhaustive}
Assertion is triggered if invalid enum value is encountered.
\begin{codelisting}
switch (order.paymentMethod)
{
case PaymentMethodCash:
break;
case PaymentMethodCreditCard:
break;
case PaymentMethodCheque:
break;
default:
NSAssert(NO, @"Invalid enum value");
}
\end{codelisting}
\subsection{Delegate methods always pass the sender}
A delegation method passes the sender as the first parameter. It is a good practice to use will/did paradigm.