-
-
Save pita5/3952176 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dispatch_queue_t queue = dispatch_queue_create("somequeue", DISPATCH_QUEUE_CONCURRENT); | |
dispatch_apply(1000000, queue, ^(size_t i) { | |
NSUInteger length = [self saveSomethingToDisk]; | |
NSUInteger gotLength = [self getSoemthingFromDisk]; | |
if (length != gotLength) | |
{ | |
NSLog(@"Something went wrong!"); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSUInteger)saveSomethingToDisk | |
{ | |
NSString* cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; | |
NSString* someFile = [cachesPath stringByAppendingPathComponent:@"somefile"]; | |
NSData* data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apple_rainbow_logo" ofType:@"jpg"]]; | |
BOOL ok = NO; | |
@try | |
{ | |
ok = [NSKeyedArchiver archiveRootObject:data toFile:someFile]; | |
} | |
@catch (NSException *exception) | |
{ | |
NSLog(@"Got an exception archiving"); | |
} | |
@finally | |
{ | |
NSLog(@"written %@", ok?@"OK":@"FAILED"); | |
return data.length; | |
} | |
} | |
- (NSUInteger)getSoemthingFromDisk | |
{ | |
NSString* cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; | |
NSString* someFile = [cachesPath stringByAppendingPathComponent:@"somefile"]; | |
NSData* data = nil; | |
@try { | |
data = [NSKeyedUnarchiver unarchiveObjectWithFile:someFile]; | |
} | |
@catch (NSException *exception) { | |
NSLog(@"Got an exception unarchiving"); | |
} | |
@finally | |
{ | |
NSLog(@"retreived %@",data?@"OK":@"FAILED"); | |
return data?data.length:0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment