This file contains 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
// Dial-up modem image loading using canvas. Relive the glory days of the internet | |
// | |
// Usage: | |
// <canvas class="image-canvas" width="180" height="180" data-image="http://lorempixel.com/180/180/"> | |
// <p>Image alt textc</p> | |
// </canvas> | |
// | |
window.onload = function() { | |
var elements = document.getElementsByClassName("image-canvas"); |
This file contains 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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// Create a 4MB in-memory, 32MB disk cache | |
NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:4*1024*1024 | |
diskCapacity:32*1024*1024 | |
diskPath:@"app_cache"]; | |
// Set the shared cache to our new instance | |
[NSURLCache setSharedURLCache:cache]; | |
} |
This file contains 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)applicationDidReceiveMemoryWarning:(UIApplication *)application { | |
[[NSURLCache sharedURLCache] removeAllCachedResponses]; | |
} |
This file contains 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
NSURLRequest *urlReq = [NSURLRequest requestWithURL:url | |
cachePolicy:NSURLRequestReturnCacheDataElseLoad | |
timeoutInterval:30.0]; | |
AFHTTPRequestOperation *request = [[AFHTTPRequestOperation alloc] initWithRequest:urlReq]; |
This file contains 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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// Create a 4MB in-memory, 32MB disk cache | |
NSURLCache *cache = [[NSURLCache alloc] initWithMemoryCapacity:4*1024*1024 | |
diskCapacity:32*1024*1024 | |
diskPath:@"app_cache"]; | |
// Set the shared cache to our new instance | |
[NSURLCache setSharedURLCache:cache]; | |
} |
This file contains 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
NSURL *url = [NSURL URLWithString:@"http://content.guardianapis.com/search?format=json"]; | |
NSURLRequest *request = [NSURLRequest requestWithURL:url]; | |
// Prepare the operation with completion handlers | |
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { | |
NSLog(@"Latest stories: %@", [JSON valueForKeyPath:@"response.results"]); | |
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){ | |
NSLog(@"There was a problem: %@", [error localizedDescription]); | |
}]; |
This file contains 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
@implementation Article | |
- (id)initWithDictionary:(NSDictionary *)dictionary { | |
self = [self init]; | |
if (self != nil) { | |
self.title = jsonObject[@"title"]; | |
self.body = jsonObject[@"body"]; | |
self.url = [NSURL URLWithString:jsonObject[@"url"]]; | |
self.dateModified = [self.dateFormatter dateFromString:jsonObject[@"modified"]]; | |
// etc etc etc |
This file contains 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
@interface Article : MTLModel <MTLJSONSerializing> | |
@property (nonatomic) NSString *title; | |
@property (nonatomic) NSString *body; | |
@property (nonatomic) NSURL *url; | |
@property (nonatmoic) NSDate *dateModified; | |
@implementation Article |
This file contains 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
(lldb) po [[[UIApp delegate] window] recursiveDescription] | |
$6 = 0x0a596190 <UIWindow: 0xa58b880; frame = (0 0; 768 1024)[...] | |
| <UILayoutContainerView: 0xc0a8460; frame = (0 0; 768 1024)[...] | |
| | <UINavigationTransitionView: 0xc0aa8e0; frame = (0 0; 768 1024)[...] | |
| | | <UIViewControllerWrapperView: 0xc1b99f0; frame = (0 20; 768 1004)[...] | |
| | | | <UIView: 0xc1a96c0; frame = (0 0; 768 1004)[...] |