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
- (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]; | |
} |
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
- (CSMCacheResponse *)cachedResponseForRequestURL:(NSURL *)url | |
{ | |
__block CSMCacheResponse* cachedResponse = nil; | |
__weak CSMCache* weakSelf = self; | |
dispatch_sync(requestQueue, ^{ | |
// Keep the weak self until function returns | |
__strong CSMCache* strongSelf = weakSelf; | |
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
__block CSMCacheResponse* cachedResponse = nil; | |
__weak CSMCache* weakSelf = self; | |
dispatch_sync(requestQueue, ^{ | |
// Keep the weak self until function returns | |
__strong CSMCache* strongSelf = weakSelf; | |
// assign cachedResponse | |
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_block_t block; | |
if (x) { | |
struct Block __tmp_1 = ...; // setup details | |
block = &__tmp_1; | |
} else { | |
struct Block __tmp_2 = ...; // setup details | |
block = &__tmp_2; | |
} |
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
@try | |
{ | |
[NSKeyedArchiver archiveRootObject:cache | |
toFile:cachePath]; | |
} | |
@catch (NSException *exception) | |
{ | |
} | |
@finally |
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
@try | |
{ | |
[NSKeyedArchiver archiveRootObject:cache | |
toFile:cachePath]; | |
} | |
@catch (NSException *exception) | |
{ | |
} | |
@finally |
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
// | |
// CSMPOSTConnectionProtocol.m | |
// ConciseEvents | |
// | |
// Created by Matthew Wilkinson on 17/10/2012. | |
// Copyright (c) 2012 Concise Media. All rights reserved. | |
// | |
#import "CSMPOSTConnectionProtocol.h" | |
#import "CSMNetworkManager.h" |
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
for (int i = 0; i < 100; i++) | |
{ | |
NSMutableURLRequest* postRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://mastercard.cmdapp.com/Services/Html.asmx/GetHtml"]]; | |
[postRequest setHTTPMethod:@"POST"]; | |
[postRequest setHTTPBody:[@"{ moduleID : 1}" dataUsingEncoding:NSUTF8StringEncoding]]; | |
[postRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | |
__autoreleasing NSHTTPURLResponse* response = nil; | |
NSData* postData = [NSURLConnection sendSynchronousRequest:postRequest |
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
// | |
// RNCachingURL.m | |
// | |
// Created by Robert Napier on 1/10/12. | |
// Copyright (c) 2012 Rob Napier. | |
// | |
// This code is licensed under the MIT License: | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the "Software"), |
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
if ([NSThread isMainThread]) | |
{ | |
[NSKeyedArchiver archiveRootObject:cache toFile:cachePath]; | |
} | |
else | |
{ | |
dispatch_sync(dispatch_get_main_queue(), ^{ | |
[NSKeyedArchiver archiveRootObject:cache toFile:cachePath]; | |
}); | |
} |