Skip to content

Instantly share code, notes, and snippets.

- (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];
}
- (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;
__block CSMCacheResponse* cachedResponse = nil;
__weak CSMCache* weakSelf = self;
dispatch_sync(requestQueue, ^{
// Keep the weak self until function returns
__strong CSMCache* strongSelf = weakSelf;
// assign cachedResponse
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;
}
@try
{
[NSKeyedArchiver archiveRootObject:cache
toFile:cachePath];
}
@catch (NSException *exception)
{
}
@finally
@try
{
[NSKeyedArchiver archiveRootObject:cache
toFile:cachePath];
}
@catch (NSException *exception)
{
}
@finally
//
// 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"
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
//
// 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"),
if ([NSThread isMainThread])
{
[NSKeyedArchiver archiveRootObject:cache toFile:cachePath];
}
else
{
dispatch_sync(dispatch_get_main_queue(), ^{
[NSKeyedArchiver archiveRootObject:cache toFile:cachePath];
});
}