Skip to content

Instantly share code, notes, and snippets.

@thisandagain
Created August 31, 2012 18:06
Show Gist options
  • Save thisandagain/3556659 to your computer and use it in GitHub Desktop.
Save thisandagain/3556659 to your computer and use it in GitHub Desktop.
Remove runtime hacking
//
// UIImage+Storage.h
// storage
//
// Created by Andrew Sliwinski on 6/23/12.
// Copyright (c) 2012 DIY, Co. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "EDStorageManager.h"
@interface UIImage (Storage)
- (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;
- (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;
- (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;
@end
//
// UIImage+Storage.m
// storage
//
// Created by Andrew Sliwinski on 6/23/12.
// Copyright (c) 2012 DIY, Co. All rights reserved.
//
#import "UIImage+Storage.h"
@implementation UIImage (Storage)
#pragma mark - Public methods
- (void)persistToCache:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure
{
[[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryCache success:^(NSURL *url, NSUInteger size) {
success(url, size);
} failure:^(NSError *error) {
failure(error);
}];
}
- (void)persistToTemp:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure
{
[[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryTemp success:^(NSURL *url, NSUInteger size) {
success(url, size);
} failure:^(NSError *error) {
failure(error);
}];
}
- (void)persistToDocuments:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure
{
[[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryDocuments success:^(NSURL *url, NSUInteger size) {
success(url, size);
} failure:^(NSError *error) {
failure(error);
}];
}
#pragma mark - Private methods
- (NSData *)jpgRepresentation
{
return UIImageJPEGRepresentation(self, 0.8f);
}
#pragma mark - Dealloc
- (void)dealloc
{
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment