diff --git a/Cocoa Programming Guidelines.pdf b/Cocoa Programming Guidelines.pdf index 93482f2..70caf3c 100644 Binary files a/Cocoa Programming Guidelines.pdf and b/Cocoa Programming Guidelines.pdf differ diff --git a/Cocoa Programming Guidelines.tex b/Cocoa Programming Guidelines.tex index 50f02d7..7c85fd6 100644 --- a/Cocoa Programming Guidelines.tex +++ b/Cocoa Programming Guidelines.tex @@ -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.