Permalink
Browse files

Merge branch 'master' of https://github.com/lavoy/ALToolkit

  • Loading branch information...
lavoy committed Jan 2, 2014
2 parents f00716e + 74c520f commit bcd870f0bc46248a5411530ac929dc081208645a
@@ -10,6 +10,10 @@
@implementation NSArray (ALToolkitAdditions)
- (id)safeObjectAtIndex:(NSUInteger)index {
+ if (![self isKindOfClass:[NSArray class]]) {
+ return nil;
+ }
+
id object = nil;
if ([self count] > index) {
@@ -10,12 +10,23 @@
@implementation NSDictionary (ALToolkitAdditions)
- (id)safeObjectForKey:(NSString *)key class:(Class)class {
+ if (![self isKindOfClass:[NSDictionary class]]) {
+ return nil;
+ }
+
id obj = nil;
if ([self isKindOfClass:[NSDictionary class]]) {
if ([[self objectForKey:key] isKindOfClass:class]) {
obj = [self objectForKey:key];
}
}
+
+ if (class == [NSString class]) {
+ if ([obj isEqualToString:@""]) {
+ obj = nil;
+ }
+ }
+
return obj;
}
@@ -11,5 +11,6 @@
+ (id)objectForKey:(NSString *)defaultName;
+ (void)setObject:(id)object forKey:(NSString *)key completion:(void (^)(void))completionBlock;
++ (void)setObjectsForKeys:(NSDictionary *)dictionary completion:(void (^)(void))completionBlock;
@end
@@ -28,4 +28,20 @@ + (void)setObject:(id)object forKey:(NSString *)key completion:(void (^)(void))c
}
++ (void)setObjectsForKeys:(NSDictionary *)dictionary completion:(void (^)(void))completionBlock {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
+ [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
+ [[NSUserDefaults standardUserDefaults] setObject:object forKey:key];
+ }];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+
+ if (completionBlock) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ completionBlock();
+ });
+ }
+ });
+}
+
+
@end

0 comments on commit bcd870f

Please sign in to comment.