mirror of
https://github.com/wnagrodzki/CocoaProgrammingGuidelines.git
synced 2025-05-03 17:41:51 +02:00
Adds "Enums do not start with zero value" and "Switch statements are exhaustive" sections.
This commit is contained in:
parent
0e5b6d5b26
commit
cac1b0b524
2 changed files with 36 additions and 1 deletions
Binary file not shown.
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue