Skip to content

Instantly share code, notes, and snippets.

@pita5
Created October 25, 2012 11:18
Show Gist options
  • Save pita5/3952059 to your computer and use it in GitHub Desktop.
Save pita5/3952059 to your computer and use it in GitHub Desktop.
- (void)saveSomethingToDisk
{
NSString* cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString* someFile = [cachesPath stringByAppendingFormat:@"somefile"];
NSData* data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"apple_rainbow_logo" ofType:@"jpg"]];
@try
{
[NSKeyedArchiver archiveRootObject:data toFile:someFile];
}
@catch (NSException *exception)
{
NSLog(@"Got an exception");
}
@finally
{
NSLog(@"written");
}
}
for (int i = 0; i < 100; i++)
{
if (i%2==0)
{
NSLog(@"main thread");
[self saveSomethingToDisk];
}
else
{
NSLog(@"background");
[self performSelectorInBackground:@selector(saveSomethingToDisk) withObject:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment