Created
August 31, 2012 18:06
-
-
Save thisandagain/3556659 to your computer and use it in GitHub Desktop.
Remove runtime hacking
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
// | |
// 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 |
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
// | |
// 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