Skip to content

Commit

Permalink
Add -[NSDictionary safeObjectForKey:]
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Oct 16, 2012
1 parent f811900 commit 6ff11e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions SSToolkit/NSDictionary+SSToolkitAdditions.h
Expand Up @@ -37,6 +37,7 @@
*/
- (NSString *)stringWithFormEncodedComponents;


///--------------------------
/// @name Deriving New Arrays
///--------------------------
Expand All @@ -52,6 +53,7 @@
*/
- (NSMutableDictionary *)deepMutableCopy NS_RETURNS_RETAINED;


///--------------
/// @name Hashing
///--------------
Expand All @@ -76,4 +78,18 @@
*/
- (NSString *)SHA1Sum;


///------------------------
/// @name Accessing Objects
///------------------------

/**
Returns the object for the specified key or `nil` if the value is `[NSNull null]`.
@param key The key used to look up the object in the receiver.
@return The object for the specified key or `nil` if the value is `[NSNull null]`.
*/
- (id)safeObjectForKey:(id)key;

@end
9 changes: 9 additions & 0 deletions SSToolkit/NSDictionary+SSToolkitAdditions.m
Expand Up @@ -77,6 +77,15 @@ - (NSString *)SHA1Sum {
return [[self _prehashData] SHA1Sum];
}


- (id)safeObjectForKey:(id)key {
id value = [self valueForKey:key];
if (value == [NSNull null]) {
return nil;
}
return value;
}

@end


Expand Down

0 comments on commit 6ff11e7

Please sign in to comment.