mirror of
https://github.com/wnagrodzki/CocoaProgrammingGuidelines.git
synced 2025-05-06 19:11:47 +02:00
Updates the way error codes are defined and fixes three typos.
This commit is contained in:
parent
2ea0081930
commit
1d740e0666
2 changed files with 6 additions and 5 deletions
Binary file not shown.
|
@ -662,9 +662,10 @@ Therefore you should always check if the return value is \inlinecode{nil} or \in
|
||||||
A custom error have both the error domain and error code defined.
|
A custom error have both the error domain and error code defined.
|
||||||
|
|
||||||
\begin{codelisting}
|
\begin{codelisting}
|
||||||
extern NSString *const MyErrorDomain;
|
extern NSString * const MyErrorDomain;
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, MyErrorCode) {
|
enum : NSUInteger
|
||||||
|
{
|
||||||
MyErrorCode1,
|
MyErrorCode1,
|
||||||
MyErrorCode2,
|
MyErrorCode2,
|
||||||
MyUnknownErrorCode,
|
MyUnknownErrorCode,
|
||||||
|
@ -676,17 +677,17 @@ Both parameters including localised description are used during an error initial
|
||||||
\begin{codelisting}
|
\begin{codelisting}
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
if(error_situation_1) {
|
if(error_situation_1) {
|
||||||
error* = [NSError errorWithDomain:MyErrorDomain
|
*error = [NSError errorWithDomain:MyErrorDomain
|
||||||
code:MyErrorCode1
|
code:MyErrorCode1
|
||||||
userInfo:@{NSLocalizedDescriptionKey: @"Description of error 1"}];
|
userInfo:@{NSLocalizedDescriptionKey: @"Description of error 1"}];
|
||||||
}
|
}
|
||||||
else if (error_situation_2) {
|
else if (error_situation_2) {
|
||||||
error* = [NSError errorWithDomain:MyErrorDomain
|
*error = [NSError errorWithDomain:MyErrorDomain
|
||||||
code:MyErrorCode2
|
code:MyErrorCode2
|
||||||
userInfo:@{NSLocalizedDescriptionKey: @"Description of error 2"}];
|
userInfo:@{NSLocalizedDescriptionKey: @"Description of error 2"}];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error* = [NSError errorWithDomain:MyErrorDomain
|
*error = [NSError errorWithDomain:MyErrorDomain
|
||||||
code:MyUnknownErrorCode
|
code:MyUnknownErrorCode
|
||||||
userInfo:@{NSLocalizedDescriptionKey: @"Unknown error"}];
|
userInfo:@{NSLocalizedDescriptionKey: @"Unknown error"}];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue