Skip to content

Commit

Permalink
Add error creation method with dictionary parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Apr 8, 2014
1 parent 99e7856 commit 5381b4b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 7 additions & 3 deletions CoconutKit/Sources/Core/HLSError.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
//

/**
* Lightweight abstract subclass of HLSError providing a convenient way to create errors and to define and access
* their properties.
* Lightweight subclass of HLSError providing a convenient way to create errors and to define and access their
* properties.
*
* This class enforces the link between accessor methods and underlying userInfo dictionary keys. This is not
* required, as explained in the documentation:
* http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html
*
* Designated initializer: -initWithDomain:Code:
* Designated initializer: -initWithDomain:code:userInfo:
*/
@interface HLSError : NSError

+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)userInfo;

/**
* Instantiate an error with some code within a domain. The error is created with no information, use the mutators below to
* add the information you need
Expand All @@ -30,6 +32,8 @@
*/
+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code localizedDescription:(NSString *)localizedDescription;

- (id)initWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)userInfo;

/**
* Initialize an error with some code within a domain. The error is created with no information, use the mutators below to
* add the information you need
Expand Down
14 changes: 12 additions & 2 deletions CoconutKit/Sources/Core/HLSError.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ @implementation HLSError

#pragma mark Class methods

+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)userInfo
{
return [[[[self class] alloc] initWithDomain:domain code:code userInfo:userInfo] autorelease];
}

+ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code
{
return [[[[self class] alloc] initWithDomain:domain code:code] autorelease];
Expand All @@ -40,14 +45,19 @@ + (id)errorWithDomain:(NSString *)domain code:(NSInteger)code localizedDescripti

#pragma mark Object creation and destruction

- (id)initWithDomain:(NSString *)domain code:(NSInteger)code
- (id)initWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)userInfo
{
if ((self = [super initWithDomain:domain code:code userInfo:nil /* not used */])) {
self.internalUserInfo = [NSDictionary dictionary];
self.internalUserInfo = userInfo ?: [NSDictionary dictionary];
}
return self;
}

- (id)initWithDomain:(NSString *)domain code:(NSInteger)code
{
return [self initWithDomain:domain code:code userInfo:nil];
}

- (void)dealloc
{
self.internalUserInfo = nil;
Expand Down

0 comments on commit 5381b4b

Please sign in to comment.