Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add -[NSDictionary safeObjectForKey:]

  • Loading branch information...
commit 6ff11e7294025fc22d42e667aba000baf4895ff8 1 parent f811900
@soffes soffes authored
View
16 SSToolkit/NSDictionary+SSToolkitAdditions.h
@@ -37,6 +37,7 @@
*/
- (NSString *)stringWithFormEncodedComponents;
+
///--------------------------
/// @name Deriving New Arrays
///--------------------------
@@ -52,6 +53,7 @@
*/
- (NSMutableDictionary *)deepMutableCopy NS_RETURNS_RETAINED;
+
///--------------
/// @name Hashing
///--------------
@@ -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
View
9 SSToolkit/NSDictionary+SSToolkitAdditions.m
@@ -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

0 comments on commit 6ff11e7

Please sign in to comment.
Something went wrong with that request. Please try again.