├── .gitignore ├── EDStorage.podspec ├── EDStorage ├── EDStorage.h ├── EDStorageManager.h ├── EDStorageManager.m ├── EDStorageOperation.h ├── EDStorageOperation.m ├── NSData+Storage.h ├── NSData+Storage.m ├── NSDictionary+Storage.h ├── NSDictionary+Storage.m ├── UIImage+Storage.h └── UIImage+Storage.m ├── LICENSE.md ├── README.md └── example ├── Base.xcconfig ├── Debug.xcconfig ├── Default-568h@2x.png ├── Release.xcconfig ├── storage.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── storage ├── EDAppDelegate.h ├── EDAppDelegate.m ├── EDViewController.h ├── EDViewController.m ├── Images │ └── nayn.png ├── en.lproj │ ├── EDViewController.xib │ └── InfoPlist.strings ├── main.m ├── storage-Info.plist └── storage-Prefix.pch └── storageTests ├── en.lproj └── InfoPlist.strings ├── storageTests-Info.plist ├── storageTests.h └── storageTests.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *~.nib 4 | 5 | build/ 6 | 7 | .xcodeproj/ 8 | !*.xcodeproj/project.pbxproj 9 | *.mode1v3 10 | *.mode2v3 11 | 12 | xcuserdata 13 | -------------------------------------------------------------------------------- /EDStorage.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'EDStorage' 3 | s.version = '0.2.2' 4 | s.license = 'Apache 2.0' 5 | s.summary = 'An iOS library for fast, easy, and safe threaded disk I/O.' 6 | s.homepage = 'https://github.com/thisandagain/storage' 7 | s.authors = {'Andrew Sliwinski' => 'andrew@diy.org'} 8 | s.source = { :git => 'https://github.com/thisandagain/storage.git', :tag => 'v0.2.2' } 9 | s.platform = :ios 10 | s.source_files = 'EDStorage' 11 | s.requires_arc = true 12 | end 13 | -------------------------------------------------------------------------------- /EDStorage/EDStorage.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDStorage.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import "NSData+Storage.h" 10 | #import "UIImage+Storage.h" 11 | #import "NSDictionary+Storage.h" -------------------------------------------------------------------------------- /EDStorage/EDStorageManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDStorageManager.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EDStorageOperation.h" 11 | 12 | // 13 | 14 | #define DEFINE_SHARED_INSTANCE_USING_BLOCK(block) \ 15 | static dispatch_once_t pred = 0; \ 16 | __strong static id _sharedObject = nil; \ 17 | dispatch_once(&pred, ^{ \ 18 | _sharedObject = block(); \ 19 | }); \ 20 | return _sharedObject; \ 21 | 22 | // 23 | 24 | typedef enum 25 | { 26 | EDStorageDirectoryCache, 27 | EDStorageDirectoryTemp, 28 | EDStorageDirectoryDocuments 29 | } Location; 30 | 31 | @interface EDStorageManager : NSObject 32 | { 33 | @private NSOperationQueue *_queue; 34 | } 35 | 36 | + (EDStorageManager *)sharedInstance; 37 | - (void)persistData:(id)data withExtension:(NSString *)ext toLocation:(Location)location success:(void *)success failure:(void *)failure; 38 | 39 | @end -------------------------------------------------------------------------------- /EDStorage/EDStorageManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // EDStorageManager.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import "EDStorageManager.h" 10 | 11 | // 12 | 13 | @interface EDStorageManager () 14 | @property (nonatomic, retain) NSOperationQueue *queue; 15 | @end 16 | 17 | // 18 | 19 | @implementation EDStorageManager 20 | 21 | @synthesize queue = _queue; 22 | 23 | #pragma mark - Init 24 | 25 | + (EDStorageManager *)sharedInstance 26 | { 27 | DEFINE_SHARED_INSTANCE_USING_BLOCK(^{ 28 | return [[self alloc] init]; 29 | }); 30 | } 31 | 32 | - (id)init 33 | { 34 | self = [super init]; 35 | if (self) 36 | { 37 | _queue = [[NSOperationQueue alloc] init]; 38 | self.queue.maxConcurrentOperationCount = 2; 39 | } 40 | return self; 41 | } 42 | 43 | #pragma mark - Public methods 44 | 45 | /** 46 | * Generic persistence adapter for category extensions. 47 | * 48 | * @param {id} Data 49 | * @param {NSString} File extension (e.g. @"jpg") 50 | * @param {Location} File location (see interface for enum) 51 | * @param {block} Success block 52 | * @param {block} Failure block 53 | * 54 | * @return {void} 55 | */ 56 | - (void)persistData:(id)data withExtension:(NSString *)ext toLocation:(Location)location success:(void *)success failure:(void *)failure 57 | { 58 | // Transpose blocks 59 | void (^successBlock)(NSURL *url, NSUInteger size) = (__bridge void (^)(NSURL *, NSUInteger))(success); 60 | void (^failureBlock)(NSError *error) = (__bridge void (^)(NSError *))(failure); 61 | 62 | // Create URL 63 | NSURL *url = [self createAssetFileURLForLocation:location withExtension:ext]; 64 | 65 | // Perform operation 66 | EDStorageOperation *operation = [[EDStorageOperation alloc] initWithData:data forURL:url]; 67 | 68 | // Completion block is manually nilled out to break the retain cycle 69 | #pragma clang diagnostic push 70 | #pragma clang diagnostic ignored "-Warc-retain-cycles" 71 | [operation setCompletionBlock:^{ 72 | if (operation.complete) 73 | { 74 | successBlock(operation.target, operation.size); 75 | } else { 76 | if (operation.error != NULL) 77 | { 78 | failureBlock(operation.error); 79 | } else { 80 | failureBlock([NSError errorWithDomain:@"com.ed.storage" code:100 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:url, @"url", nil]]); 81 | } 82 | } 83 | 84 | // 85 | 86 | [operation setCompletionBlock:nil]; // Force dealloc 87 | }]; 88 | #pragma clang diagnostic pop 89 | 90 | [self.queue addOperation:operation]; 91 | } 92 | 93 | #pragma mark - Private methods 94 | 95 | /** 96 | * Creates an asset file url (path) using location declaration and file extension. 97 | * 98 | * @param {Location} ENUM type 99 | * @param {NSString} Extension (e.g. @"jpg") 100 | * 101 | * @return {NSURL} 102 | */ 103 | - (NSURL *)createAssetFileURLForLocation:(Location)location withExtension:(NSString *)extension 104 | { 105 | NSArray *paths = nil; 106 | NSString *directory = nil; 107 | 108 | switch (location) { 109 | case EDStorageDirectoryCache: 110 | paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 111 | directory = [paths objectAtIndex:0]; 112 | break; 113 | case EDStorageDirectoryTemp: 114 | directory = NSTemporaryDirectory(); 115 | break; 116 | case EDStorageDirectoryDocuments: 117 | paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 118 | directory = [paths objectAtIndex:0]; 119 | break; 120 | default: 121 | [NSException raise:@"Invalid location value" format:@"Location %u is invalid", location]; 122 | break; 123 | } 124 | 125 | NSString *assetName = [NSString stringWithFormat:@"%@.%@", [[NSProcessInfo processInfo] globallyUniqueString], extension]; 126 | NSString *assetPath = [directory stringByAppendingPathComponent:assetName]; 127 | 128 | return [NSURL fileURLWithPath:assetPath]; 129 | } 130 | 131 | #pragma mark - Dealloc 132 | 133 | - (void)dealloc 134 | { 135 | _queue = nil; 136 | } 137 | 138 | @end -------------------------------------------------------------------------------- /EDStorage/EDStorageOperation.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDStorageOperation.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface EDStorageOperation : NSOperation 12 | { 13 | id dataset; 14 | } 15 | 16 | @property (atomic, retain) NSURL *target; 17 | @property (atomic, assign) NSUInteger size; 18 | @property (atomic, assign) BOOL complete; 19 | @property (atomic, retain) NSError *error; 20 | 21 | - (id)initWithData:(id)data forURL:(NSURL *)url; 22 | 23 | @end -------------------------------------------------------------------------------- /EDStorage/EDStorageOperation.m: -------------------------------------------------------------------------------- 1 | // 2 | // EDStorageOperation.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import "EDStorageOperation.h" 10 | 11 | @implementation EDStorageOperation 12 | 13 | @synthesize target = _target; 14 | @synthesize size = _size; 15 | @synthesize complete = _complete; 16 | @synthesize error = _error; 17 | 18 | #pragma mark - Init 19 | 20 | - (id)initWithData:(id)data forURL:(NSURL *)url 21 | { 22 | self = [super init]; 23 | if (!self) return nil; 24 | 25 | dataset = data; 26 | _size = [dataset length]; 27 | _complete = false; 28 | 29 | _target = [[NSURL alloc] init]; 30 | self.target = url; 31 | 32 | _error = [[NSError alloc] init]; 33 | self.error = NULL; 34 | 35 | return self; 36 | } 37 | 38 | #pragma mark - Inherit 39 | 40 | - (void)main 41 | { 42 | @autoreleasepool { 43 | NSError *err; 44 | self.complete = [dataset writeToURL:self.target options:NSDataWritingAtomic error:&err]; 45 | if (err) { 46 | _error = err; 47 | } 48 | } 49 | } 50 | 51 | #pragma mark - Dealloc 52 | 53 | - (void)dealloc 54 | { 55 | dataset = nil; 56 | 57 | _target = nil; 58 | _error = nil; 59 | } 60 | 61 | @end -------------------------------------------------------------------------------- /EDStorage/NSData+Storage.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Storage.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/24/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EDStorageManager.h" 11 | 12 | @interface NSData (Storage) 13 | 14 | - (void)persistToCacheWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 15 | - (void)persistToTempWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 16 | - (void)persistToDocumentsWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 17 | 18 | @end -------------------------------------------------------------------------------- /EDStorage/NSData+Storage.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Storage.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/24/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import "NSData+Storage.h" 10 | 11 | @implementation NSData (Storage) 12 | 13 | - (void)persistToCacheWithExtension:(NSString *)extension success:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 14 | { 15 | [[EDStorageManager sharedInstance] persistData:self withExtension:extension toLocation:EDStorageDirectoryCache success:(void *)([success copy]) failure:(void *)([failure copy])]; 16 | } 17 | 18 | - (void)persistToTempWithExtension:(NSString *)extension success:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 19 | { 20 | [[EDStorageManager sharedInstance] persistData:self withExtension:extension toLocation:EDStorageDirectoryTemp success:(void *)([success copy]) failure:(void *)([failure copy])]; 21 | } 22 | 23 | - (void)persistToDocumentsWithExtension:(NSString *)extension success:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 24 | { 25 | [[EDStorageManager sharedInstance] persistData:self withExtension:extension toLocation:EDStorageDirectoryDocuments success:(void *)([success copy]) failure:(void *)([failure copy])]; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /EDStorage/NSDictionary+Storage.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+Storage.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 12/5/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EDStorageManager.h" 11 | 12 | @interface NSDictionary (Storage) 13 | 14 | - (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 15 | - (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 16 | - (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /EDStorage/NSDictionary+Storage.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDictionary+Storage.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 12/5/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import "NSDictionary+Storage.h" 10 | 11 | @implementation NSDictionary (Storage) 12 | 13 | #pragma mark - Public methods 14 | 15 | - (void)persistToCache:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 16 | { 17 | [[EDStorageManager sharedInstance] persistData:[self representation] withExtension:@"plist" toLocation:EDStorageDirectoryTemp success:(void *)([success copy]) failure:(void *)([failure copy])]; 18 | } 19 | 20 | - (void)persistToTemp:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 21 | { 22 | [[EDStorageManager sharedInstance] persistData:[self representation] withExtension:@"plist" toLocation:EDStorageDirectoryTemp success:(void *)([success copy]) failure:(void *)([failure copy])]; 23 | } 24 | 25 | - (void)persistToDocuments:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 26 | { 27 | [[EDStorageManager sharedInstance] persistData:[self representation] withExtension:@"plist" toLocation:EDStorageDirectoryDocuments success:(void *)([success copy]) failure:(void *)([failure copy])]; 28 | } 29 | 30 | #pragma mark - Private methods 31 | 32 | - (NSData *)representation 33 | { 34 | return [[self description] dataUsingEncoding:NSUTF16StringEncoding]; 35 | } 36 | 37 | @end -------------------------------------------------------------------------------- /EDStorage/UIImage+Storage.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Storage.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EDStorageManager.h" 11 | 12 | @interface UIImage (Storage) 13 | 14 | - (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 15 | - (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 16 | - (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 17 | 18 | @end -------------------------------------------------------------------------------- /EDStorage/UIImage+Storage.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Storage.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 DIY, Co. All rights reserved. 7 | // 8 | 9 | #import "UIImage+Storage.h" 10 | 11 | @implementation UIImage (Storage) 12 | 13 | #pragma mark - Public methods 14 | 15 | - (void)persistToCache:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 16 | { 17 | [[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryTemp success:(void *)([success copy]) failure:(void *)([failure copy])]; 18 | } 19 | 20 | - (void)persistToTemp:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 21 | { 22 | [[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryTemp success:(void *)([success copy]) failure:(void *)([failure copy])]; 23 | } 24 | 25 | - (void)persistToDocuments:(void (^)(NSURL *, NSUInteger))success failure:(void (^)(NSError *))failure 26 | { 27 | [[EDStorageManager sharedInstance] persistData:[self jpgRepresentation] withExtension:@"jpg" toLocation:EDStorageDirectoryDocuments success:(void *)([success copy]) failure:(void *)([failure copy])]; 28 | } 29 | 30 | #pragma mark - Private methods 31 | 32 | - (NSData *)jpgRepresentation 33 | { 34 | return UIImageJPEGRepresentation(self, 0.8f); 35 | } 36 | 37 | @end -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Andrew Sliwinski 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Storage 2 | #### Persist all the things! Wheee! 3 | 4 | In attempting to keep things [DRY](http://en.wikipedia.org/wiki/Don't_repeat_yourself), EDStorage was created to address the fair amount of boilerplate that often gets created to deal with writing data to disk within iOS applications in a performant manner. Disk I/O within iOS is synchronous and so much of this boilerplate is often written to improve performance by moving I/O to a background thread. EDStorage accomplishes this by transforming each write instance into a `NSOperation` which is managed by a single `NSOperationQueue`. All of this is done in the background while providing high-level methods to the user via categories. 5 | 6 | **EDStorage strives to provide three things:** 7 | - An abstract interface based on categories that makes persisting data to disk simple. 8 | - A highly generic management interface that makes extending EDStorage equally simple. 9 | - Speed and safety. 10 | 11 | ## Basic Use 12 | The easiest way to get going with EDStorage is to take a look at the included example application. The Xcode project file can be found in `example > storage.xcodeproj`. 13 | 14 | In order to include EDStorage in your project, you'll want to add the entirety of the `EDStorage` directory to your project. EDStorage is built on top of foundation libraries and so no additional frameworks are needed. To bring in all of the included storage categories, simply: 15 | 16 | ```objective-c 17 | #import "EDStorage.h" 18 | ``` 19 | 20 | Each category has a slightly different interface depending on the needs of a specific class, but to use a common example, let's look at how to persist a UIImage to the application cache directory: 21 | 22 | ```objective-c 23 | - (void)doSomething 24 | { 25 | UIImage *image = [UIImage imageNamed:@"keyboardCat.png"]; 26 | 27 | [image persistToCache:^(NSURL *url, NSUInteger size) { 28 | NSLog(@"FTW!: %@ | %d bytes", url, size); 29 | } failure:^(NSError *error) { 30 | NSLog(@"UH OH: %@", error); 31 | }]; 32 | } 33 | ``` 34 | 35 | Persisting to the temporary and documents application directories is equaly simple: 36 | 37 | ```objective-c 38 | [image persistToTemp:^(NSURL *url, NSUInteger size) { 39 | NSLog(@"FTW!: %@ | %d bytes", url, size); 40 | } failure:^(NSError *error) { 41 | NSLog(@"UH OH: %@", error); 42 | }]; 43 | ``` 44 | 45 | ```objective-c 46 | [image persistToDocuments:^(NSURL *url, NSUInteger size) { 47 | NSLog(@"FTW!: %@ | %d bytes", url, size); 48 | } failure:^(NSError *error) { 49 | NSLog(@"UH OH: %@", error); 50 | }]; 51 | ``` 52 | 53 | ## Implementing A Storage Category 54 | `EDStorageManager` provides a single block method for interfacing with categories: 55 | 56 | ```objective-c 57 | - (void)persistData:(id)data withExtension:(NSString *)ext toLocation:(Location)location success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 58 | ``` 59 | 60 | Categories simply abstract the process of calling this method on `EDStorageManager` by handling conversion of the class instance into a NSData object. See the `NSData+Storage` implementation For example, the storage category for UIImage simply passes self into NSData by calling `UIImageJPEGRepresentation()`. 61 | 62 | **If you create a category that you find useful, please let me know! Pull requests are welcome.** 63 | 64 | --- 65 | 66 | ## Locations 67 | ```objective-c 68 | EDStorageDirectoryCache 69 | EDStorageDirectoryTemp 70 | EDStorageDirectoryDocuments 71 | ``` 72 | 73 | ## NSData+Storage Methods 74 | ```objective-c 75 | - (void)persistToCacheWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 76 | - (void)persistToTempWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 77 | - (void)persistToDocumentsWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 78 | ``` 79 | 80 | ## NSDictionary+Storage Methods 81 | ```objective-c 82 | - (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 83 | - (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 84 | - (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 85 | ``` 86 | 87 | ## UIImage+Storage Methods 88 | ```objective-c 89 | - (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 90 | - (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 91 | - (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure; 92 | ``` 93 | 94 | --- 95 | 96 | ## iOS Support 97 | EDStorage is tested on iOS 5 and up. Older versions of iOS may work but are not currently supported. 98 | 99 | ## ARC 100 | EDStorage as of v0.2.0 is built using ARC. If you are including EDStorage in a project that **does not** use [Automatic Reference Counting (ARC)](http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html), you will need to set the `-fobjc-arc` compiler flag on all of the EDStorage source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. Now select all EDStorage source files, press Enter, insert `-fobjc-arc` and then "Done" to enable ARC for EDStorage. 101 | -------------------------------------------------------------------------------- /example/Base.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Base.xcconfig 3 | // DIY 4 | // 5 | // Created by Patrick Piemonte on 3/26/13. 6 | // Copyright (c) 2013 DIY. All rights reserved. 7 | // 8 | 9 | PRODUCT_NAME = DIY 10 | WRAPPER_EXTENSION = app 11 | 12 | ARCHS[sdk=iphoneos*] = $(ARCHS_UNIVERSAL_IPHONE_OS) 13 | 14 | SKIP_INSTALL = NO 15 | 16 | DEAD_CODE_STRIPPING = YES; 17 | 18 | OTHER_CFLAGS = -fconstant-cfstrings 19 | DEBUG_INFORMATION_FORMAT = dwarf-with-dsym 20 | 21 | INFOPLIST_FILE = Resources/DIY-Info.plist 22 | 23 | GCC_PREFIX_HEADER = Resources/DIY-Prefix.pch 24 | GCC_PRECOMPILE_PREFIX_HEADER = YES 25 | GCC_C_LANGUAGE_STANDARD = c99 26 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0 27 | 28 | CLANG_ENABLE_OBJC_ARC = YES 29 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES 30 | CLANG_WARN_EMPTY_BODY = YES 31 | CLANG_WARN_CONSTANT_CONVERSION = YES 32 | CLANG_WARN_ENUM_CONVERSION = YES 33 | CLANG_WARN_INT_CONVERSION = YES 34 | GCC_ENABLE_OBJC_EXCEPTIONS = NO -------------------------------------------------------------------------------- /example/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Debug.xcconfig 3 | // DIY 4 | // 5 | // Created by Patrick Piemonte on 3/26/13. 6 | // Copyright (c) 2013 DIY. All rights reserved. 7 | // 8 | 9 | #include "Base.xcconfig" 10 | 11 | GCC_OPTIMIZATION_LEVEL = 0 12 | GCC_TREAT_WARNINGS_AS_ERRORS = YES 13 | GCC_WARN_UNUSED_VARIABLE = YES 14 | GCC_WARN_ABOUT_RETURN_TYPE = YES 15 | GCC_WARN_ABOUT_MISSING_PROTOTYPES[sdk=iphone*] = YES 16 | GCC_WARN_SHADOW[sdk=iphone*] = YES 17 | GCC_PREPROCESSOR_DEFINITIONS = $(INHERITED) DEBUG=1 18 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES 19 | CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES 20 | CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS[sdk=iphone*]=YES 21 | 22 | ALWAYS_SEARCH_USER_PATHS = NO 23 | COPY_PHASE_STRIP = NO 24 | ONLY_ACTIVE_ARCH = YES 25 | 26 | OTHER_CFLAGS[sdk=iphone*] = $(OTHER_CFLAGS) -Wall -Wconversion -Wundeclared-selector -Wobjc-autosynthesis-property-ivar-name-match 27 | -------------------------------------------------------------------------------- /example/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisandagain/storage/b805cc26187d790c91ab2dff41aec0e6a1d915fa/example/Default-568h@2x.png -------------------------------------------------------------------------------- /example/Release.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Release.xcconfig 3 | // DIY 4 | // 5 | // Created by Patrick Piemonte on 3/26/13. 6 | // Copyright (c) 2013 DIY. All rights reserved. 7 | // 8 | 9 | #include "Base.xcconfig" 10 | 11 | GCC_OPTIMIZATION_LEVEL = s 12 | GCC_PREPROCESSOR_DEFINITIONS = _LIBCPP_VISIBLE= NDEBUG=1 NS_BLOCK_ASSERTIONS=1 13 | 14 | DEAD_CODE_STRIPPING = YES 15 | COPY_PHASE_STRIP = YES 16 | 17 | OTHER_CFLAGS[sdk=iphone*] = $(OTHER_CFLAGS) -DNS_BLOCK_ASSERTIONS=1 18 | 19 | VALIDATE_PRODUCT = YES 20 | -------------------------------------------------------------------------------- /example/storage.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C30D48D91670314800C45DC8 /* NSDictionary+Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = C30D48D81670314800C45DC8 /* NSDictionary+Storage.m */; }; 11 | C30D48DA1670314800C45DC8 /* NSDictionary+Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = C30D48D81670314800C45DC8 /* NSDictionary+Storage.m */; }; 12 | C32B9BF8159659B900AD3365 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9BF7159659B900AD3365 /* UIKit.framework */; }; 13 | C32B9BFA159659B900AD3365 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9BF9159659B900AD3365 /* Foundation.framework */; }; 14 | C32B9BFC159659B900AD3365 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9BFB159659B900AD3365 /* CoreGraphics.framework */; }; 15 | C32B9C02159659B900AD3365 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C32B9C00159659B900AD3365 /* InfoPlist.strings */; }; 16 | C32B9C04159659B900AD3365 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C32B9C03159659B900AD3365 /* main.m */; }; 17 | C32B9C08159659B900AD3365 /* EDAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C32B9C07159659B900AD3365 /* EDAppDelegate.m */; }; 18 | C32B9C0B159659B900AD3365 /* EDViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C32B9C0A159659B900AD3365 /* EDViewController.m */; }; 19 | C32B9C0E159659B900AD3365 /* EDViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C32B9C0C159659B900AD3365 /* EDViewController.xib */; }; 20 | C32B9C16159659B900AD3365 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9C15159659B900AD3365 /* SenTestingKit.framework */; }; 21 | C32B9C17159659B900AD3365 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9BF7159659B900AD3365 /* UIKit.framework */; }; 22 | C32B9C18159659B900AD3365 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C32B9BF9159659B900AD3365 /* Foundation.framework */; }; 23 | C32B9C20159659B900AD3365 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C32B9C1E159659B900AD3365 /* InfoPlist.strings */; }; 24 | C32B9C23159659B900AD3365 /* storageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C32B9C22159659B900AD3365 /* storageTests.m */; }; 25 | C32B9C3715965E2C00AD3365 /* nayn.png in Resources */ = {isa = PBXBuildFile; fileRef = C32B9C3615965E2C00AD3365 /* nayn.png */; }; 26 | C3678283171D1AC700117ABA /* Base.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678280171D1AC700117ABA /* Base.xcconfig */; }; 27 | C3678284171D1AC700117ABA /* Base.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678280171D1AC700117ABA /* Base.xcconfig */; }; 28 | C3678285171D1AC700117ABA /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678281171D1AC700117ABA /* Debug.xcconfig */; }; 29 | C3678286171D1AC700117ABA /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678281171D1AC700117ABA /* Debug.xcconfig */; }; 30 | C3678287171D1AC700117ABA /* Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678282171D1AC700117ABA /* Release.xcconfig */; }; 31 | C3678288171D1AC700117ABA /* Release.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = C3678282171D1AC700117ABA /* Release.xcconfig */; }; 32 | C367828A171FBC7300117ABA /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C3678289171FBC7300117ABA /* Default-568h@2x.png */; }; 33 | C37C5CD91597D0120089F8C4 /* LICENSE.md in Resources */ = {isa = PBXBuildFile; fileRef = C37C5CD71597D0110089F8C4 /* LICENSE.md */; }; 34 | C37C5CDA1597D0120089F8C4 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = C37C5CD81597D0110089F8C4 /* README.md */; }; 35 | DE49BE9B15B8BAA6005BB13A /* EDStorageManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DE49BE9415B8BAA6005BB13A /* EDStorageManager.m */; }; 36 | DE49BE9C15B8BAA6005BB13A /* EDStorageOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = DE49BE9615B8BAA6005BB13A /* EDStorageOperation.m */; }; 37 | DE49BE9D15B8BAA6005BB13A /* NSData+Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE49BE9815B8BAA6005BB13A /* NSData+Storage.m */; }; 38 | DE49BE9E15B8BAA6005BB13A /* UIImage+Storage.m in Sources */ = {isa = PBXBuildFile; fileRef = DE49BE9A15B8BAA6005BB13A /* UIImage+Storage.m */; }; 39 | /* End PBXBuildFile section */ 40 | 41 | /* Begin PBXContainerItemProxy section */ 42 | C32B9C19159659B900AD3365 /* PBXContainerItemProxy */ = { 43 | isa = PBXContainerItemProxy; 44 | containerPortal = C32B9BEA159659B800AD3365 /* Project object */; 45 | proxyType = 1; 46 | remoteGlobalIDString = C32B9BF2159659B900AD3365; 47 | remoteInfo = storage; 48 | }; 49 | /* End PBXContainerItemProxy section */ 50 | 51 | /* Begin PBXFileReference section */ 52 | C30D48D71670314800C45DC8 /* NSDictionary+Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDictionary+Storage.h"; path = "../EDStorage/NSDictionary+Storage.h"; sourceTree = ""; }; 53 | C30D48D81670314800C45DC8 /* NSDictionary+Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDictionary+Storage.m"; path = "../EDStorage/NSDictionary+Storage.m"; sourceTree = ""; }; 54 | C32B9BF3159659B900AD3365 /* storage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = storage.app; sourceTree = BUILT_PRODUCTS_DIR; }; 55 | C32B9BF7159659B900AD3365 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 56 | C32B9BF9159659B900AD3365 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 57 | C32B9BFB159659B900AD3365 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 58 | C32B9BFF159659B900AD3365 /* storage-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "storage-Info.plist"; sourceTree = ""; }; 59 | C32B9C01159659B900AD3365 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 60 | C32B9C03159659B900AD3365 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 61 | C32B9C05159659B900AD3365 /* storage-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "storage-Prefix.pch"; sourceTree = ""; }; 62 | C32B9C06159659B900AD3365 /* EDAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EDAppDelegate.h; sourceTree = ""; }; 63 | C32B9C07159659B900AD3365 /* EDAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EDAppDelegate.m; sourceTree = ""; }; 64 | C32B9C09159659B900AD3365 /* EDViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EDViewController.h; sourceTree = ""; }; 65 | C32B9C0A159659B900AD3365 /* EDViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EDViewController.m; sourceTree = ""; }; 66 | C32B9C0D159659B900AD3365 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/EDViewController.xib; sourceTree = ""; }; 67 | C32B9C14159659B900AD3365 /* storageTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = storageTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | C32B9C15159659B900AD3365 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; 69 | C32B9C1D159659B900AD3365 /* storageTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "storageTests-Info.plist"; sourceTree = ""; }; 70 | C32B9C1F159659B900AD3365 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 71 | C32B9C21159659B900AD3365 /* storageTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = storageTests.h; sourceTree = ""; }; 72 | C32B9C22159659B900AD3365 /* storageTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = storageTests.m; sourceTree = ""; }; 73 | C32B9C3615965E2C00AD3365 /* nayn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = nayn.png; path = Images/nayn.png; sourceTree = ""; }; 74 | C3678280171D1AC700117ABA /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = ""; }; 75 | C3678281171D1AC700117ABA /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 76 | C3678282171D1AC700117ABA /* Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 77 | C3678289171FBC7300117ABA /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "../Default-568h@2x.png"; sourceTree = ""; }; 78 | C37C5CD71597D0110089F8C4 /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE.md; path = ../LICENSE.md; sourceTree = ""; }; 79 | C37C5CD81597D0110089F8C4 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = README.md; path = ../README.md; sourceTree = ""; }; 80 | DE49BE9215B8BAA6005BB13A /* EDStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EDStorage.h; path = ../EDStorage/EDStorage.h; sourceTree = ""; }; 81 | DE49BE9315B8BAA6005BB13A /* EDStorageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EDStorageManager.h; path = ../EDStorage/EDStorageManager.h; sourceTree = ""; }; 82 | DE49BE9415B8BAA6005BB13A /* EDStorageManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EDStorageManager.m; path = ../EDStorage/EDStorageManager.m; sourceTree = ""; }; 83 | DE49BE9515B8BAA6005BB13A /* EDStorageOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EDStorageOperation.h; path = ../EDStorage/EDStorageOperation.h; sourceTree = ""; }; 84 | DE49BE9615B8BAA6005BB13A /* EDStorageOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EDStorageOperation.m; path = ../EDStorage/EDStorageOperation.m; sourceTree = ""; }; 85 | DE49BE9715B8BAA6005BB13A /* NSData+Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+Storage.h"; path = "../EDStorage/NSData+Storage.h"; sourceTree = ""; }; 86 | DE49BE9815B8BAA6005BB13A /* NSData+Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+Storage.m"; path = "../EDStorage/NSData+Storage.m"; sourceTree = ""; }; 87 | DE49BE9915B8BAA6005BB13A /* UIImage+Storage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImage+Storage.h"; path = "../EDStorage/UIImage+Storage.h"; sourceTree = ""; }; 88 | DE49BE9A15B8BAA6005BB13A /* UIImage+Storage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImage+Storage.m"; path = "../EDStorage/UIImage+Storage.m"; sourceTree = ""; }; 89 | /* End PBXFileReference section */ 90 | 91 | /* Begin PBXFrameworksBuildPhase section */ 92 | C32B9BF0159659B900AD3365 /* Frameworks */ = { 93 | isa = PBXFrameworksBuildPhase; 94 | buildActionMask = 2147483647; 95 | files = ( 96 | C32B9BF8159659B900AD3365 /* UIKit.framework in Frameworks */, 97 | C32B9BFA159659B900AD3365 /* Foundation.framework in Frameworks */, 98 | C32B9BFC159659B900AD3365 /* CoreGraphics.framework in Frameworks */, 99 | ); 100 | runOnlyForDeploymentPostprocessing = 0; 101 | }; 102 | C32B9C10159659B900AD3365 /* Frameworks */ = { 103 | isa = PBXFrameworksBuildPhase; 104 | buildActionMask = 2147483647; 105 | files = ( 106 | C32B9C16159659B900AD3365 /* SenTestingKit.framework in Frameworks */, 107 | C32B9C17159659B900AD3365 /* UIKit.framework in Frameworks */, 108 | C32B9C18159659B900AD3365 /* Foundation.framework in Frameworks */, 109 | ); 110 | runOnlyForDeploymentPostprocessing = 0; 111 | }; 112 | /* End PBXFrameworksBuildPhase section */ 113 | 114 | /* Begin PBXGroup section */ 115 | C32B9BE8159659B800AD3365 = { 116 | isa = PBXGroup; 117 | children = ( 118 | DE49BE9215B8BAA6005BB13A /* EDStorage.h */, 119 | DE49BE9315B8BAA6005BB13A /* EDStorageManager.h */, 120 | DE49BE9415B8BAA6005BB13A /* EDStorageManager.m */, 121 | DE49BE9515B8BAA6005BB13A /* EDStorageOperation.h */, 122 | DE49BE9615B8BAA6005BB13A /* EDStorageOperation.m */, 123 | DE49BE9715B8BAA6005BB13A /* NSData+Storage.h */, 124 | DE49BE9815B8BAA6005BB13A /* NSData+Storage.m */, 125 | DE49BE9915B8BAA6005BB13A /* UIImage+Storage.h */, 126 | DE49BE9A15B8BAA6005BB13A /* UIImage+Storage.m */, 127 | C30D48D71670314800C45DC8 /* NSDictionary+Storage.h */, 128 | C30D48D81670314800C45DC8 /* NSDictionary+Storage.m */, 129 | C37C5CD71597D0110089F8C4 /* LICENSE.md */, 130 | C37C5CD81597D0110089F8C4 /* README.md */, 131 | C3678280171D1AC700117ABA /* Base.xcconfig */, 132 | C3678281171D1AC700117ABA /* Debug.xcconfig */, 133 | C3678282171D1AC700117ABA /* Release.xcconfig */, 134 | C32B9BFD159659B900AD3365 /* storage */, 135 | C32B9C1B159659B900AD3365 /* storageTests */, 136 | C32B9BF6159659B900AD3365 /* Frameworks */, 137 | C32B9BF4159659B900AD3365 /* Products */, 138 | ); 139 | sourceTree = ""; 140 | }; 141 | C32B9BF4159659B900AD3365 /* Products */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | C32B9BF3159659B900AD3365 /* storage.app */, 145 | C32B9C14159659B900AD3365 /* storageTests.octest */, 146 | ); 147 | name = Products; 148 | sourceTree = ""; 149 | }; 150 | C32B9BF6159659B900AD3365 /* Frameworks */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | C32B9BF7159659B900AD3365 /* UIKit.framework */, 154 | C32B9BF9159659B900AD3365 /* Foundation.framework */, 155 | C32B9BFB159659B900AD3365 /* CoreGraphics.framework */, 156 | C32B9C15159659B900AD3365 /* SenTestingKit.framework */, 157 | ); 158 | name = Frameworks; 159 | sourceTree = ""; 160 | }; 161 | C32B9BFD159659B900AD3365 /* storage */ = { 162 | isa = PBXGroup; 163 | children = ( 164 | C32B9C06159659B900AD3365 /* EDAppDelegate.h */, 165 | C32B9C07159659B900AD3365 /* EDAppDelegate.m */, 166 | C32B9C09159659B900AD3365 /* EDViewController.h */, 167 | C32B9C0A159659B900AD3365 /* EDViewController.m */, 168 | C32B9C0C159659B900AD3365 /* EDViewController.xib */, 169 | C32B9BFE159659B900AD3365 /* Supporting Files */, 170 | C32B9C3515965A9800AD3365 /* Images */, 171 | ); 172 | path = storage; 173 | sourceTree = ""; 174 | }; 175 | C32B9BFE159659B900AD3365 /* Supporting Files */ = { 176 | isa = PBXGroup; 177 | children = ( 178 | C32B9BFF159659B900AD3365 /* storage-Info.plist */, 179 | C32B9C00159659B900AD3365 /* InfoPlist.strings */, 180 | C32B9C03159659B900AD3365 /* main.m */, 181 | C32B9C05159659B900AD3365 /* storage-Prefix.pch */, 182 | ); 183 | name = "Supporting Files"; 184 | sourceTree = ""; 185 | }; 186 | C32B9C1B159659B900AD3365 /* storageTests */ = { 187 | isa = PBXGroup; 188 | children = ( 189 | C32B9C21159659B900AD3365 /* storageTests.h */, 190 | C32B9C22159659B900AD3365 /* storageTests.m */, 191 | C32B9C1C159659B900AD3365 /* Supporting Files */, 192 | ); 193 | path = storageTests; 194 | sourceTree = ""; 195 | }; 196 | C32B9C1C159659B900AD3365 /* Supporting Files */ = { 197 | isa = PBXGroup; 198 | children = ( 199 | C32B9C1D159659B900AD3365 /* storageTests-Info.plist */, 200 | C32B9C1E159659B900AD3365 /* InfoPlist.strings */, 201 | ); 202 | name = "Supporting Files"; 203 | sourceTree = ""; 204 | }; 205 | C32B9C3515965A9800AD3365 /* Images */ = { 206 | isa = PBXGroup; 207 | children = ( 208 | C3678289171FBC7300117ABA /* Default-568h@2x.png */, 209 | C32B9C3615965E2C00AD3365 /* nayn.png */, 210 | ); 211 | name = Images; 212 | sourceTree = ""; 213 | }; 214 | /* End PBXGroup section */ 215 | 216 | /* Begin PBXNativeTarget section */ 217 | C32B9BF2159659B900AD3365 /* storage */ = { 218 | isa = PBXNativeTarget; 219 | buildConfigurationList = C32B9C26159659B900AD3365 /* Build configuration list for PBXNativeTarget "storage" */; 220 | buildPhases = ( 221 | C32B9BEF159659B900AD3365 /* Sources */, 222 | C32B9BF0159659B900AD3365 /* Frameworks */, 223 | C32B9BF1159659B900AD3365 /* Resources */, 224 | ); 225 | buildRules = ( 226 | ); 227 | dependencies = ( 228 | ); 229 | name = storage; 230 | productName = storage; 231 | productReference = C32B9BF3159659B900AD3365 /* storage.app */; 232 | productType = "com.apple.product-type.application"; 233 | }; 234 | C32B9C13159659B900AD3365 /* storageTests */ = { 235 | isa = PBXNativeTarget; 236 | buildConfigurationList = C32B9C29159659B900AD3365 /* Build configuration list for PBXNativeTarget "storageTests" */; 237 | buildPhases = ( 238 | C32B9C0F159659B900AD3365 /* Sources */, 239 | C32B9C10159659B900AD3365 /* Frameworks */, 240 | C32B9C11159659B900AD3365 /* Resources */, 241 | C32B9C12159659B900AD3365 /* ShellScript */, 242 | ); 243 | buildRules = ( 244 | ); 245 | dependencies = ( 246 | C32B9C1A159659B900AD3365 /* PBXTargetDependency */, 247 | ); 248 | name = storageTests; 249 | productName = storageTests; 250 | productReference = C32B9C14159659B900AD3365 /* storageTests.octest */; 251 | productType = "com.apple.product-type.bundle"; 252 | }; 253 | /* End PBXNativeTarget section */ 254 | 255 | /* Begin PBXProject section */ 256 | C32B9BEA159659B800AD3365 /* Project object */ = { 257 | isa = PBXProject; 258 | attributes = { 259 | CLASSPREFIX = ED; 260 | LastUpgradeCheck = 0460; 261 | ORGANIZATIONNAME = "DIY, Co."; 262 | }; 263 | buildConfigurationList = C32B9BED159659B900AD3365 /* Build configuration list for PBXProject "storage" */; 264 | compatibilityVersion = "Xcode 3.2"; 265 | developmentRegion = English; 266 | hasScannedForEncodings = 0; 267 | knownRegions = ( 268 | en, 269 | ); 270 | mainGroup = C32B9BE8159659B800AD3365; 271 | productRefGroup = C32B9BF4159659B900AD3365 /* Products */; 272 | projectDirPath = ""; 273 | projectRoot = ""; 274 | targets = ( 275 | C32B9BF2159659B900AD3365 /* storage */, 276 | C32B9C13159659B900AD3365 /* storageTests */, 277 | ); 278 | }; 279 | /* End PBXProject section */ 280 | 281 | /* Begin PBXResourcesBuildPhase section */ 282 | C32B9BF1159659B900AD3365 /* Resources */ = { 283 | isa = PBXResourcesBuildPhase; 284 | buildActionMask = 2147483647; 285 | files = ( 286 | C32B9C02159659B900AD3365 /* InfoPlist.strings in Resources */, 287 | C32B9C0E159659B900AD3365 /* EDViewController.xib in Resources */, 288 | C32B9C3715965E2C00AD3365 /* nayn.png in Resources */, 289 | C37C5CD91597D0120089F8C4 /* LICENSE.md in Resources */, 290 | C37C5CDA1597D0120089F8C4 /* README.md in Resources */, 291 | C3678283171D1AC700117ABA /* Base.xcconfig in Resources */, 292 | C3678285171D1AC700117ABA /* Debug.xcconfig in Resources */, 293 | C3678287171D1AC700117ABA /* Release.xcconfig in Resources */, 294 | C367828A171FBC7300117ABA /* Default-568h@2x.png in Resources */, 295 | ); 296 | runOnlyForDeploymentPostprocessing = 0; 297 | }; 298 | C32B9C11159659B900AD3365 /* Resources */ = { 299 | isa = PBXResourcesBuildPhase; 300 | buildActionMask = 2147483647; 301 | files = ( 302 | C32B9C20159659B900AD3365 /* InfoPlist.strings in Resources */, 303 | C3678284171D1AC700117ABA /* Base.xcconfig in Resources */, 304 | C3678286171D1AC700117ABA /* Debug.xcconfig in Resources */, 305 | C3678288171D1AC700117ABA /* Release.xcconfig in Resources */, 306 | ); 307 | runOnlyForDeploymentPostprocessing = 0; 308 | }; 309 | /* End PBXResourcesBuildPhase section */ 310 | 311 | /* Begin PBXShellScriptBuildPhase section */ 312 | C32B9C12159659B900AD3365 /* ShellScript */ = { 313 | isa = PBXShellScriptBuildPhase; 314 | buildActionMask = 2147483647; 315 | files = ( 316 | ); 317 | inputPaths = ( 318 | ); 319 | outputPaths = ( 320 | ); 321 | runOnlyForDeploymentPostprocessing = 0; 322 | shellPath = /bin/sh; 323 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; 324 | }; 325 | /* End PBXShellScriptBuildPhase section */ 326 | 327 | /* Begin PBXSourcesBuildPhase section */ 328 | C32B9BEF159659B900AD3365 /* Sources */ = { 329 | isa = PBXSourcesBuildPhase; 330 | buildActionMask = 2147483647; 331 | files = ( 332 | C32B9C04159659B900AD3365 /* main.m in Sources */, 333 | C32B9C08159659B900AD3365 /* EDAppDelegate.m in Sources */, 334 | C32B9C0B159659B900AD3365 /* EDViewController.m in Sources */, 335 | DE49BE9B15B8BAA6005BB13A /* EDStorageManager.m in Sources */, 336 | DE49BE9C15B8BAA6005BB13A /* EDStorageOperation.m in Sources */, 337 | DE49BE9D15B8BAA6005BB13A /* NSData+Storage.m in Sources */, 338 | DE49BE9E15B8BAA6005BB13A /* UIImage+Storage.m in Sources */, 339 | C30D48D91670314800C45DC8 /* NSDictionary+Storage.m in Sources */, 340 | ); 341 | runOnlyForDeploymentPostprocessing = 0; 342 | }; 343 | C32B9C0F159659B900AD3365 /* Sources */ = { 344 | isa = PBXSourcesBuildPhase; 345 | buildActionMask = 2147483647; 346 | files = ( 347 | C32B9C23159659B900AD3365 /* storageTests.m in Sources */, 348 | C30D48DA1670314800C45DC8 /* NSDictionary+Storage.m in Sources */, 349 | ); 350 | runOnlyForDeploymentPostprocessing = 0; 351 | }; 352 | /* End PBXSourcesBuildPhase section */ 353 | 354 | /* Begin PBXTargetDependency section */ 355 | C32B9C1A159659B900AD3365 /* PBXTargetDependency */ = { 356 | isa = PBXTargetDependency; 357 | target = C32B9BF2159659B900AD3365 /* storage */; 358 | targetProxy = C32B9C19159659B900AD3365 /* PBXContainerItemProxy */; 359 | }; 360 | /* End PBXTargetDependency section */ 361 | 362 | /* Begin PBXVariantGroup section */ 363 | C32B9C00159659B900AD3365 /* InfoPlist.strings */ = { 364 | isa = PBXVariantGroup; 365 | children = ( 366 | C32B9C01159659B900AD3365 /* en */, 367 | ); 368 | name = InfoPlist.strings; 369 | sourceTree = ""; 370 | }; 371 | C32B9C0C159659B900AD3365 /* EDViewController.xib */ = { 372 | isa = PBXVariantGroup; 373 | children = ( 374 | C32B9C0D159659B900AD3365 /* en */, 375 | ); 376 | name = EDViewController.xib; 377 | sourceTree = ""; 378 | }; 379 | C32B9C1E159659B900AD3365 /* InfoPlist.strings */ = { 380 | isa = PBXVariantGroup; 381 | children = ( 382 | C32B9C1F159659B900AD3365 /* en */, 383 | ); 384 | name = InfoPlist.strings; 385 | sourceTree = ""; 386 | }; 387 | /* End PBXVariantGroup section */ 388 | 389 | /* Begin XCBuildConfiguration section */ 390 | C32B9C24159659B900AD3365 /* Debug */ = { 391 | isa = XCBuildConfiguration; 392 | baseConfigurationReference = C3678281171D1AC700117ABA /* Debug.xcconfig */; 393 | buildSettings = { 394 | ALWAYS_SEARCH_USER_PATHS = NO; 395 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 396 | CLANG_WARN_CONSTANT_CONVERSION = YES; 397 | CLANG_WARN_ENUM_CONVERSION = YES; 398 | CLANG_WARN_INT_CONVERSION = YES; 399 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 400 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 401 | COPY_PHASE_STRIP = NO; 402 | GCC_C_LANGUAGE_STANDARD = gnu99; 403 | GCC_DYNAMIC_NO_PIC = NO; 404 | GCC_OPTIMIZATION_LEVEL = 0; 405 | GCC_PREPROCESSOR_DEFINITIONS = ( 406 | "DEBUG=1", 407 | "$(inherited)", 408 | ); 409 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 410 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 411 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 412 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 413 | GCC_WARN_UNUSED_VARIABLE = YES; 414 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 415 | SDKROOT = iphoneos; 416 | }; 417 | name = Debug; 418 | }; 419 | C32B9C25159659B900AD3365 /* Release */ = { 420 | isa = XCBuildConfiguration; 421 | baseConfigurationReference = C3678282171D1AC700117ABA /* Release.xcconfig */; 422 | buildSettings = { 423 | ALWAYS_SEARCH_USER_PATHS = NO; 424 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 425 | CLANG_WARN_CONSTANT_CONVERSION = YES; 426 | CLANG_WARN_ENUM_CONVERSION = YES; 427 | CLANG_WARN_INT_CONVERSION = YES; 428 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 429 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 430 | COPY_PHASE_STRIP = YES; 431 | GCC_C_LANGUAGE_STANDARD = gnu99; 432 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 433 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 434 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 435 | GCC_WARN_UNUSED_VARIABLE = YES; 436 | IPHONEOS_DEPLOYMENT_TARGET = 5.0; 437 | OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; 438 | SDKROOT = iphoneos; 439 | VALIDATE_PRODUCT = YES; 440 | }; 441 | name = Release; 442 | }; 443 | C32B9C27159659B900AD3365 /* Debug */ = { 444 | isa = XCBuildConfiguration; 445 | buildSettings = { 446 | CLANG_ENABLE_OBJC_ARC = YES; 447 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 448 | GCC_PREFIX_HEADER = "storage/storage-Prefix.pch"; 449 | INFOPLIST_FILE = "storage/storage-Info.plist"; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | WRAPPER_EXTENSION = app; 452 | }; 453 | name = Debug; 454 | }; 455 | C32B9C28159659B900AD3365 /* Release */ = { 456 | isa = XCBuildConfiguration; 457 | buildSettings = { 458 | CLANG_ENABLE_OBJC_ARC = YES; 459 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 460 | GCC_PREFIX_HEADER = "storage/storage-Prefix.pch"; 461 | INFOPLIST_FILE = "storage/storage-Info.plist"; 462 | PRODUCT_NAME = "$(TARGET_NAME)"; 463 | WRAPPER_EXTENSION = app; 464 | }; 465 | name = Release; 466 | }; 467 | C32B9C2A159659B900AD3365 /* Debug */ = { 468 | isa = XCBuildConfiguration; 469 | buildSettings = { 470 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/storage.app/storage"; 471 | FRAMEWORK_SEARCH_PATHS = ( 472 | "$(SDKROOT)/Developer/Library/Frameworks", 473 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks", 474 | ); 475 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 476 | GCC_PREFIX_HEADER = "storage/storage-Prefix.pch"; 477 | INFOPLIST_FILE = "storageTests/storageTests-Info.plist"; 478 | PRODUCT_NAME = "$(TARGET_NAME)"; 479 | TEST_HOST = "$(BUNDLE_LOADER)"; 480 | WRAPPER_EXTENSION = octest; 481 | }; 482 | name = Debug; 483 | }; 484 | C32B9C2B159659B900AD3365 /* Release */ = { 485 | isa = XCBuildConfiguration; 486 | buildSettings = { 487 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/storage.app/storage"; 488 | FRAMEWORK_SEARCH_PATHS = ( 489 | "$(SDKROOT)/Developer/Library/Frameworks", 490 | "$(DEVELOPER_LIBRARY_DIR)/Frameworks", 491 | ); 492 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 493 | GCC_PREFIX_HEADER = "storage/storage-Prefix.pch"; 494 | INFOPLIST_FILE = "storageTests/storageTests-Info.plist"; 495 | PRODUCT_NAME = "$(TARGET_NAME)"; 496 | TEST_HOST = "$(BUNDLE_LOADER)"; 497 | WRAPPER_EXTENSION = octest; 498 | }; 499 | name = Release; 500 | }; 501 | /* End XCBuildConfiguration section */ 502 | 503 | /* Begin XCConfigurationList section */ 504 | C32B9BED159659B900AD3365 /* Build configuration list for PBXProject "storage" */ = { 505 | isa = XCConfigurationList; 506 | buildConfigurations = ( 507 | C32B9C24159659B900AD3365 /* Debug */, 508 | C32B9C25159659B900AD3365 /* Release */, 509 | ); 510 | defaultConfigurationIsVisible = 0; 511 | defaultConfigurationName = Release; 512 | }; 513 | C32B9C26159659B900AD3365 /* Build configuration list for PBXNativeTarget "storage" */ = { 514 | isa = XCConfigurationList; 515 | buildConfigurations = ( 516 | C32B9C27159659B900AD3365 /* Debug */, 517 | C32B9C28159659B900AD3365 /* Release */, 518 | ); 519 | defaultConfigurationIsVisible = 0; 520 | defaultConfigurationName = Release; 521 | }; 522 | C32B9C29159659B900AD3365 /* Build configuration list for PBXNativeTarget "storageTests" */ = { 523 | isa = XCConfigurationList; 524 | buildConfigurations = ( 525 | C32B9C2A159659B900AD3365 /* Debug */, 526 | C32B9C2B159659B900AD3365 /* Release */, 527 | ); 528 | defaultConfigurationIsVisible = 0; 529 | defaultConfigurationName = Release; 530 | }; 531 | /* End XCConfigurationList section */ 532 | }; 533 | rootObject = C32B9BEA159659B800AD3365 /* Project object */; 534 | } 535 | -------------------------------------------------------------------------------- /example/storage.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/storage/EDAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDAppDelegate.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class EDViewController; 12 | 13 | @interface EDAppDelegate : UIResponder 14 | 15 | @property (strong, nonatomic) UIWindow *window; 16 | 17 | @property (strong, nonatomic) EDViewController *viewController; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /example/storage/EDAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // EDAppDelegate.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import "EDAppDelegate.h" 10 | 11 | #import "EDViewController.h" 12 | 13 | @implementation EDAppDelegate 14 | 15 | @synthesize window = _window; 16 | @synthesize viewController = _viewController; 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 21 | self.viewController = [[EDViewController alloc] initWithNibName:@"EDViewController" bundle:nil]; 22 | self.window.rootViewController = self.viewController; 23 | [self.window makeKeyAndVisible]; 24 | 25 | return YES; 26 | } 27 | 28 | - (void)applicationWillResignActive:(UIApplication *)application 29 | { 30 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 31 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 32 | } 33 | 34 | - (void)applicationDidEnterBackground:(UIApplication *)application 35 | { 36 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 37 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 38 | } 39 | 40 | - (void)applicationWillEnterForeground:(UIApplication *)application 41 | { 42 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | - (void)applicationDidBecomeActive:(UIApplication *)application 46 | { 47 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 48 | } 49 | 50 | - (void)applicationWillTerminate:(UIApplication *)application 51 | { 52 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /example/storage/EDViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // EDViewController.h 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EDStorage.h" 11 | 12 | @interface EDViewController : UIViewController 13 | 14 | @property (nonatomic, retain) IBOutlet UIImageView *sampleImage; 15 | @property (nonatomic, retain) IBOutlet UIImageView *savedImage; 16 | 17 | - (IBAction)saveToCache:(id)sender; 18 | - (IBAction)saveToTemp:(id)sender; 19 | - (IBAction)saveToDocuments:(id)sender; 20 | 21 | @end -------------------------------------------------------------------------------- /example/storage/EDViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // EDViewController.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import "EDViewController.h" 10 | 11 | @implementation EDViewController 12 | 13 | @synthesize sampleImage = _sampleImage; 14 | @synthesize savedImage = _savedImage; 15 | 16 | #pragma mark - View lifecycle 17 | 18 | - (void)viewDidLoad 19 | { 20 | [super viewDidLoad]; 21 | 22 | // 23 | 24 | UIImage *image = [UIImage imageNamed:@"nayn.png"]; 25 | NSData *data = [[NSData alloc] initWithData:UIImagePNGRepresentation(image)]; 26 | [data persistToDocumentsWithExtension:@"png" success:^(NSURL *url, NSUInteger size) { 27 | NSLog(@"Complete: %@ | %d", url, size); 28 | } failure:^(NSError *error) { 29 | NSLog(@"Error: %@", error); 30 | }]; 31 | } 32 | 33 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 34 | { 35 | return (interfaceOrientation == UIInterfaceOrientationPortrait); 36 | } 37 | 38 | #pragma mark - UI events 39 | 40 | - (IBAction)saveToCache:(id)sender 41 | { 42 | [self.sampleImage.image persistToCache:^(NSURL *url, NSUInteger size) { 43 | NSLog(@"Complete: %@ | %d", url, size); 44 | [self updateSavedImagePreview:[url path]]; 45 | } failure:^(NSError *error) { 46 | NSLog(@"Error: %@", error); 47 | }]; 48 | } 49 | 50 | - (IBAction)saveToTemp:(id)sender 51 | { 52 | [self.sampleImage.image persistToTemp:^(NSURL *url, NSUInteger size) { 53 | NSLog(@"Complete: %@ | %d", url, size); 54 | [self updateSavedImagePreview:[url path]]; 55 | } failure:^(NSError *error) { 56 | NSLog(@"Error: %@", error); 57 | }]; 58 | } 59 | 60 | - (IBAction)saveToDocuments:(id)sender 61 | { 62 | [self.sampleImage.image persistToDocuments:^(NSURL *url, NSUInteger size) { 63 | NSLog(@"Complete: %@ | %d", url, size); 64 | [self updateSavedImagePreview:[url path]]; 65 | } failure:^(NSError *error) { 66 | NSLog(@"Error: %@", error); 67 | }]; 68 | } 69 | 70 | #pragma mark - Render 71 | 72 | - (void)updateSavedImagePreview:(NSString *)relativePath 73 | { 74 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ 75 | 76 | UIImage *image = [UIImage imageWithContentsOfFile:relativePath]; 77 | 78 | dispatch_sync(dispatch_get_main_queue(), ^{ 79 | self.savedImage.image = image; 80 | }); 81 | 82 | }); 83 | } 84 | 85 | #pragma mark - Dealloc 86 | 87 | - (void)releaseObjects 88 | { 89 | _sampleImage = nil; 90 | _savedImage = nil; 91 | } 92 | 93 | - (void)viewDidUnload 94 | { 95 | [super viewDidUnload]; 96 | [self releaseObjects]; 97 | } 98 | 99 | - (void)dealloc 100 | { 101 | [self releaseObjects]; 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /example/storage/Images/nayn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thisandagain/storage/b805cc26187d790c91ab2dff41aec0e6a1d915fa/example/storage/Images/nayn.png -------------------------------------------------------------------------------- /example/storage/en.lproj/EDViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 1296 5 | 11E53 6 | 2549 7 | 1138.47 8 | 569.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 1498 12 | 13 | 14 | IBProxyObject 15 | IBUIButton 16 | IBUIImageView 17 | IBUILabel 18 | IBUIView 19 | 20 | 21 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 22 | 23 | 24 | PluginDependencyRecalculationVersion 25 | 26 | 27 | 28 | 29 | IBFilesOwner 30 | IBCocoaTouchFramework 31 | 32 | 33 | IBFirstResponder 34 | IBCocoaTouchFramework 35 | 36 | 37 | 38 | 274 39 | 40 | 41 | 42 | 319 43 | {{20, 20}, {280, 187}} 44 | 45 | 46 | 47 | _NS:9 48 | YES 49 | 2 50 | NO 51 | IBCocoaTouchFramework 52 | 53 | NSImage 54 | nayn.png 55 | 56 | 57 | 58 | 59 | 310 60 | {{20, 20}, {84, 57}} 61 | 62 | 63 | 64 | _NS:9 65 | 66 | 1 67 | MC45MDk4MDM5MjE2IDAuMzIxNTY4NjI3NSAwLjA1NDkwMTk2MDc4AA 68 | 69 | NO 70 | IBCocoaTouchFramework 71 | 72 | 73 | 74 | 292 75 | {{20, 291}, {136, 21}} 76 | 77 | 78 | 79 | _NS:9 80 | NO 81 | YES 82 | 7 83 | NO 84 | IBCocoaTouchFramework 85 | Save To: 86 | 87 | 1 88 | MCAwIDAAA 89 | 90 | 91 | 0 92 | 10 93 | 94 | 1 95 | 14 96 | 97 | 98 | Helvetica 99 | 14 100 | 16 101 | 102 | 103 | 104 | 105 | 292 106 | {{20, 313}, {280, 37}} 107 | 108 | 109 | 110 | _NS:9 111 | NO 112 | IBCocoaTouchFramework 113 | 0 114 | 0 115 | 1 116 | Temp Directory 117 | 118 | 3 119 | MQA 120 | 121 | 122 | 1 123 | MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA 124 | 125 | 126 | 3 127 | MC41AA 128 | 129 | 130 | 2 131 | 15 132 | 133 | 134 | Helvetica-Bold 135 | 15 136 | 16 137 | 138 | 139 | 140 | 141 | 292 142 | {{20, 358}, {280, 37}} 143 | 144 | 145 | 146 | _NS:9 147 | NO 148 | IBCocoaTouchFramework 149 | 0 150 | 0 151 | 1 152 | Caches Directory 153 | 154 | 155 | 1 156 | MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 292 165 | {{20, 403}, {280, 37}} 166 | 167 | 168 | _NS:9 169 | NO 170 | IBCocoaTouchFramework 171 | 0 172 | 0 173 | 1 174 | Documents Directory 175 | 176 | 177 | 1 178 | MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA 179 | 180 | 181 | 182 | 183 | 184 | 185 | {{0, 20}, {320, 460}} 186 | 187 | 188 | 189 | 190 | 3 191 | MC43NQA 192 | 193 | 2 194 | 195 | 196 | NO 197 | 198 | IBCocoaTouchFramework 199 | 200 | 201 | 202 | 203 | 204 | 205 | view 206 | 207 | 208 | 209 | 7 210 | 211 | 212 | 213 | savedImage 214 | 215 | 216 | 217 | 27 218 | 219 | 220 | 221 | sampleImage 222 | 223 | 224 | 225 | 25 226 | 227 | 228 | 229 | saveToTemp: 230 | 231 | 232 | 7 233 | 234 | 23 235 | 236 | 237 | 238 | saveToCache: 239 | 240 | 241 | 7 242 | 243 | 20 244 | 245 | 246 | 247 | saveToDocuments: 248 | 249 | 250 | 7 251 | 252 | 30 253 | 254 | 255 | 256 | 257 | 258 | 0 259 | 260 | 261 | 262 | 263 | 264 | -1 265 | 266 | 267 | File's Owner 268 | 269 | 270 | -2 271 | 272 | 273 | 274 | 275 | 6 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 28 289 | 290 | 291 | 292 | 293 | 18 294 | 295 | 296 | 297 | 298 | 17 299 | 300 | 301 | 302 | 303 | 19 304 | 305 | 306 | 307 | 308 | 26 309 | 310 | 311 | 312 | 313 | 8 314 | 315 | 316 | 317 | 318 | 319 | 320 | EDViewController 321 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 322 | UIResponder 323 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 324 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 325 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 326 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 327 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 328 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 329 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 330 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 331 | 332 | 333 | 334 | 335 | 336 | 31 337 | 338 | 339 | 340 | 341 | EDViewController 342 | UIViewController 343 | 344 | id 345 | id 346 | id 347 | 348 | 349 | 350 | saveToCache: 351 | id 352 | 353 | 354 | saveToDocuments: 355 | id 356 | 357 | 358 | saveToTemp: 359 | id 360 | 361 | 362 | 363 | UIImageView 364 | UIImageView 365 | 366 | 367 | 368 | sampleImage 369 | UIImageView 370 | 371 | 372 | savedImage 373 | UIImageView 374 | 375 | 376 | 377 | IBProjectSource 378 | ./Classes/EDViewController.h 379 | 380 | 381 | 382 | 383 | 0 384 | IBCocoaTouchFramework 385 | 386 | com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS 387 | 388 | 389 | YES 390 | 3 391 | 392 | nayn.png 393 | {1440, 900} 394 | 395 | 1498 396 | 397 | 398 | -------------------------------------------------------------------------------- /example/storage/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /example/storage/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // storage 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "EDAppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([EDAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/storage/storage-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.diy.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/storage/storage-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'storage' target in the 'storage' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_4_0 8 | #warning "This project uses features only available in iOS SDK 4.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /example/storageTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /example/storageTests/storageTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.diy.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /example/storageTests/storageTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // storageTests.h 3 | // storageTests 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface storageTests : SenTestCase 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /example/storageTests/storageTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // storageTests.m 3 | // storageTests 4 | // 5 | // Created by Andrew Sliwinski on 6/23/12. 6 | // Copyright (c) 2012 Andrew Sliwinski. All rights reserved. 7 | // 8 | 9 | #import "storageTests.h" 10 | 11 | @implementation storageTests 12 | 13 | - (void)setUp 14 | { 15 | [super setUp]; 16 | 17 | // Set-up code here. 18 | } 19 | 20 | - (void)tearDown 21 | { 22 | // Tear-down code here. 23 | 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample 28 | { 29 | STFail(@"Unit tests are not implemented yet in storageTests"); 30 | } 31 | 32 | @end 33 | --------------------------------------------------------------------------------