├── .gitignore ├── IOSBoilerplate.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── IOSBoilerplate ├── AFNetworking │ ├── AFHTTPClient.h │ ├── AFHTTPClient.m │ ├── AFHTTPRequestOperation.h │ ├── AFHTTPRequestOperation.m │ ├── AFImageCache.h │ ├── AFImageCache.m │ ├── AFImageRequestOperation.h │ ├── AFImageRequestOperation.m │ ├── AFJSONRequestOperation.h │ ├── AFJSONRequestOperation.m │ ├── AFNetworkActivityIndicatorManager.h │ ├── AFNetworkActivityIndicatorManager.m │ ├── AFNetworking.h │ ├── AFPropertyListRequestOperation.h │ ├── AFPropertyListRequestOperation.m │ ├── AFURLConnectionOperation.h │ ├── AFURLConnectionOperation.m │ ├── AFXMLRequestOperation.h │ ├── AFXMLRequestOperation.m │ ├── UIImageView+AFNetworking.h │ └── UIImageView+AFNetworking.m ├── AFURLCache.h ├── AFURLCache.m ├── AsyncCell.h ├── AsyncCell.m ├── AsyncCellImagesExample.h ├── AsyncCellImagesExample.m ├── AsyncCellImagesExample.xib ├── AsyncImageExample.h ├── AsyncImageExample.m ├── AsyncImageExample.xib ├── AutocompleteLocationExample.h ├── AutocompleteLocationExample.m ├── AutocompleteLocationExample.xib ├── BrowserSampleViewController.h ├── BrowserSampleViewController.m ├── BrowserSampleViewController.xib ├── BrowserViewController.h ├── BrowserViewController.m ├── BrowserViewController.xib ├── DataHelper.h ├── DataHelper.m ├── DictionaryHelper.h ├── DictionaryHelper.m ├── DirectionsExample.h ├── DirectionsExample.m ├── DirectionsExample.xib ├── EGORefreshTableHeaderView.h ├── EGORefreshTableHeaderView.m ├── FastCell.h ├── FastCell.m ├── HTTPHUDExample.h ├── HTTPHUDExample.m ├── HTTPHUDExample.xib ├── IOSBoilerplate-Info.plist ├── IOSBoilerplate-Prefix.pch ├── IOSBoilerplateAppDelegate.h ├── IOSBoilerplateAppDelegate.m ├── JSONKit.h ├── JSONKit.m ├── ListViewController.h ├── ListViewController.m ├── MyApplication.h ├── MyApplication.m ├── PullDownExample.h ├── PullDownExample.m ├── PullDownExample.xib ├── RootViewController.h ├── RootViewController.m ├── SVProgressHUD │ ├── .DS_Store │ ├── SVProgressHUD.bundle │ │ ├── error.png │ │ ├── error@2x.png │ │ ├── success.png │ │ └── success@2x.png │ ├── SVProgressHUD.h │ └── SVProgressHUD.m ├── StringHelper.h ├── StringHelper.m ├── SwipeableCell.h ├── SwipeableCell.m ├── SwipeableTableViewExample.h ├── SwipeableTableViewExample.m ├── SwipeableTableViewExample.xib ├── TwitterSearchClient.h ├── TwitterSearchClient.m ├── VariableHeightCell.h ├── VariableHeightCell.m ├── VariableHeightExample.h ├── VariableHeightExample.m ├── VariableHeightExample.xib ├── blackArrow.png ├── blackArrow@2x.png ├── blueArrow.png ├── blueArrow@2x.png ├── en.lproj │ ├── InfoPlist.strings │ ├── MainWindow.xib │ └── RootViewController.xib ├── grayArrow.png ├── grayArrow@2x.png ├── left.png ├── left@2x.png ├── main.m ├── right.png ├── right@2x.png ├── whiteArrow.png └── whiteArrow@2x.png ├── IOSBoilerplateTests ├── IOSBoilerplateTests-Info.plist ├── IOSBoilerplateTests.h ├── IOSBoilerplateTests.m └── en.lproj │ └── InfoPlist.strings ├── README.md └── shots ├── async-cells.png ├── demo-menu.png ├── directions.png └── web-browser.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | *~.nib 4 | 5 | build/ 6 | 7 | *.pbxuser 8 | *.perspective 9 | *.perspectivev3 10 | *.mode1v3 11 | *.mode2v3 12 | xcuserdata 13 | -------------------------------------------------------------------------------- /IOSBoilerplate.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFHTTPRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFHTTPOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFURLConnectionOperation.h" 25 | #import "AFHTTPClient.h" 26 | 27 | /** 28 | `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. 29 | */ 30 | @interface AFHTTPRequestOperation : AFURLConnectionOperation { 31 | @private 32 | NSIndexSet *_acceptableStatusCodes; 33 | NSSet *_acceptableContentTypes; 34 | NSError *_HTTPError; 35 | } 36 | 37 | ///---------------------------------------------- 38 | /// @name Getting HTTP URL Connection Information 39 | ///---------------------------------------------- 40 | 41 | /** 42 | The last HTTP response received by the operation's connection. 43 | */ 44 | @property (readonly, nonatomic, retain) NSHTTPURLResponse *response; 45 | 46 | 47 | ///---------------------------------------------------------- 48 | /// @name Managing And Checking For Acceptable HTTP Responses 49 | ///---------------------------------------------------------- 50 | 51 | /** 52 | Returns an `NSIndexSet` object containing the ranges of acceptable HTTP status codes. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 53 | 54 | By default, this is the range 200 to 299, inclusive. 55 | */ 56 | @property (nonatomic, retain) NSIndexSet *acceptableStatusCodes; 57 | 58 | /** 59 | A Boolean value that corresponds to whether the status code of the response is within the specified set of acceptable status codes. Returns `YES` if `acceptableStatusCodes` is `nil`. 60 | */ 61 | @property (readonly) BOOL hasAcceptableStatusCode; 62 | 63 | /** 64 | Returns an `NSSet` object containing the acceptable MIME types. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17 65 | 66 | By default, this is `nil`. 67 | */ 68 | @property (nonatomic, retain) NSSet *acceptableContentTypes; 69 | 70 | /** 71 | A Boolean value that corresponds to whether the MIME type of the response is among the specified set of acceptable content types. Returns `YES` if `acceptableContentTypes` is `nil`. 72 | */ 73 | @property (readonly) BOOL hasAcceptableContentType; 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFHTTPRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFHTTPOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFHTTPRequestOperation.h" 24 | 25 | @interface AFHTTPRequestOperation () 26 | @property (readwrite, nonatomic, retain) NSError *error; 27 | @property (readonly, nonatomic, assign) BOOL hasContent; 28 | @end 29 | 30 | @implementation AFHTTPRequestOperation 31 | @synthesize acceptableStatusCodes = _acceptableStatusCodes; 32 | @synthesize acceptableContentTypes = _acceptableContentTypes; 33 | @synthesize error = _HTTPError; 34 | 35 | - (id)initWithRequest:(NSURLRequest *)request { 36 | self = [super initWithRequest:request]; 37 | if (!self) { 38 | return nil; 39 | } 40 | 41 | self.acceptableStatusCodes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; 42 | 43 | return self; 44 | } 45 | 46 | - (void)dealloc { 47 | [_acceptableStatusCodes release]; 48 | [_acceptableContentTypes release]; 49 | [_HTTPError release]; 50 | [super dealloc]; 51 | } 52 | 53 | - (NSHTTPURLResponse *)response { 54 | return (NSHTTPURLResponse *)[super response]; 55 | } 56 | 57 | - (NSError *)error { 58 | if (self.response) { 59 | if (![self hasAcceptableStatusCode]) { 60 | NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; 61 | [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code %@, got %d", nil), self.acceptableStatusCodes, [self.response statusCode]] forKey:NSLocalizedDescriptionKey]; 62 | [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; 63 | 64 | self.error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease]; 65 | } else if ([self hasContent] && ![self hasAcceptableContentType]) { // Don't invalidate content type if there is no content 66 | NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; 67 | [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), self.acceptableContentTypes, [self.response MIMEType]] forKey:NSLocalizedDescriptionKey]; 68 | [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; 69 | 70 | self.error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo] autorelease]; 71 | } 72 | } 73 | 74 | return _HTTPError; 75 | } 76 | 77 | - (BOOL)hasContent { 78 | return [self.responseData length] > 0; 79 | } 80 | 81 | - (BOOL)hasAcceptableStatusCode { 82 | return !self.acceptableStatusCodes || [self.acceptableStatusCodes containsIndex:[self.response statusCode]]; 83 | } 84 | 85 | - (BOOL)hasAcceptableContentType { 86 | return !self.acceptableContentTypes || [self.acceptableContentTypes containsObject:[self.response MIMEType]]; 87 | } 88 | 89 | #pragma mark - AFHTTPClientOperation 90 | 91 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 92 | return NO; 93 | } 94 | 95 | + (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest 96 | success:(void (^)(id object))success 97 | failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure 98 | { 99 | AFHTTPRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; 100 | operation.completionBlock = ^ { 101 | if ([operation isCancelled]) { 102 | return; 103 | } 104 | 105 | if (operation.error) { 106 | if (failure) { 107 | dispatch_async(dispatch_get_main_queue(), ^(void) { 108 | failure(operation.response, operation.error); 109 | }); 110 | } 111 | } else { 112 | if (success) { 113 | dispatch_async(dispatch_get_main_queue(), ^(void) { 114 | success(operation.responseData); 115 | }); 116 | } 117 | } 118 | }; 119 | 120 | return operation; 121 | } 122 | 123 | @end 124 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFImageCache.h: -------------------------------------------------------------------------------- 1 | // AFImageCache.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFImageRequestOperation.h" 25 | 26 | #import 27 | 28 | /** 29 | `AFImageCache` is an `NSCache` that stores and retrieves images from cache. 30 | 31 | @discussion `AFImageCache` is used to cache images for successful `AFImageRequestOperations` with the proper cache policy. 32 | */ 33 | @interface AFImageCache : NSCache 34 | 35 | /** 36 | Returns the shared image cache object for the system. 37 | 38 | @return The systemwide image cache. 39 | */ 40 | + (AFImageCache *)sharedImageCache; 41 | 42 | /** 43 | Returns the image associated with a given URL and cache name. 44 | 45 | @param url The URL associated with the image in the cache. 46 | @param cacheName The cache name associated with the image in the cache. This allows for multiple versions of an image to be associated for a single URL, such as image thumbnails, for instance. 47 | 48 | @return The image associated with the URL and cache name, or `nil` if not image exists. 49 | */ 50 | 51 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 52 | - (UIImage *)cachedImageForURL:(NSURL *)url 53 | cacheName:(NSString *)cacheName; 54 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 55 | - (NSImage *)cachedImageForURL:(NSURL *)url 56 | cacheName:(NSString *)cacheName; 57 | #endif 58 | 59 | /** 60 | Stores image data into cache, associated with a given URL and cache name. 61 | 62 | @param imageData The image data to be stored in cache. 63 | @param url The URL to be associated with the image. 64 | @param cacheName The cache name to be associated with the image in the cache. This allows for multiple versions of an image to be associated for a single URL, such as image thumbnails, for instance. 65 | */ 66 | - (void)cacheImageData:(NSData *)imageData 67 | forURL:(NSURL *)url 68 | cacheName:(NSString *)cacheName; 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFImageCache.m: -------------------------------------------------------------------------------- 1 | // AFImageCache.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFImageCache.h" 24 | 25 | static inline NSString * AFImageCacheKeyFromURLAndCacheName(NSURL *url, NSString *cacheName) { 26 | return [[url absoluteString] stringByAppendingFormat:@"#%@", cacheName]; 27 | } 28 | 29 | @implementation AFImageCache 30 | 31 | + (AFImageCache *)sharedImageCache { 32 | static AFImageCache *_sharedImageCache = nil; 33 | static dispatch_once_t oncePredicate; 34 | 35 | dispatch_once(&oncePredicate, ^{ 36 | _sharedImageCache = [[self alloc] init]; 37 | }); 38 | 39 | return _sharedImageCache; 40 | } 41 | 42 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 43 | - (UIImage *)cachedImageForURL:(NSURL *)url 44 | cacheName:(NSString *)cacheName 45 | { 46 | return [UIImage imageWithData:[self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)]]; 47 | } 48 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 49 | - (NSImage *)cachedImageForURL:(NSURL *)url 50 | cacheName:(NSString *)cacheName 51 | { 52 | return [[[NSImage alloc] initWithData:[self objectForKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)]] autorelease]; 53 | } 54 | #endif 55 | 56 | - (void)cacheImageData:(NSData *)imageData 57 | forURL:(NSURL *)url 58 | cacheName:(NSString *)cacheName 59 | { 60 | [self setObject:[NSPurgeableData dataWithData:imageData] forKey:AFImageCacheKeyFromURLAndCacheName(url, cacheName)]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFImageRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFImageRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFHTTPRequestOperation.h" 25 | 26 | #import 27 | 28 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 29 | #import 30 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 31 | #import 32 | #endif 33 | 34 | /** 35 | `AFImageRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading an processing images. 36 | 37 | ## Acceptable Content Types 38 | 39 | By default, `AFImageRequestOperation` accepts the following MIME types, which correspond to the image formats supported by UIImage or NSImage: 40 | 41 | - `image/tiff` 42 | - `image/jpeg` 43 | - `image/gif` 44 | - `image/png` 45 | - `image/ico` 46 | - `image/x-icon` 47 | - `image/bmp` 48 | - `image/x-bmp` 49 | - `image/x-xbitmap` 50 | - `image/x-win-bitmap` 51 | */ 52 | @interface AFImageRequestOperation : AFHTTPRequestOperation { 53 | @private 54 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 55 | UIImage *_responseImage; 56 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 57 | NSImage *_responseImage; 58 | #endif 59 | } 60 | 61 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 62 | @property (readonly, nonatomic, retain) UIImage *responseImage; 63 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 64 | @property (readonly, nonatomic, retain) NSImage *responseImage; 65 | #endif 66 | 67 | /** 68 | Creates and returns an `AFImageRequestOperation` object and sets the specified success callback. 69 | 70 | @param urlRequest The request object to be loaded asynchronously during execution of the operation. 71 | @param success A block object to be executed when the request finishes successfully. This block has no return value and takes a single arguments, the image created from the response data of the request. 72 | 73 | @return A new image request operation 74 | */ 75 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 76 | + (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 77 | success:(void (^)(UIImage *image))success; 78 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 79 | + (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 80 | success:(void (^)(NSImage *image))success; 81 | #endif 82 | 83 | /** 84 | Creates and returns an `AFImageRequestOperation` object and sets the specified success callback. 85 | 86 | @param urlRequest The request object to be loaded asynchronously during execution of the operation. 87 | @param imageProcessingBlock A block object to be executed after the image request finishes successfully, but before the image is returned in the `success` block. This block takes a single argument, the image loaded from the response body, and returns the processed image. 88 | @param cacheName The cache name to be associated with the image. `AFImageCache` associates objects by URL and cache name, allowing for multiple versions of the same image to be cached. 89 | @param success A block object to be executed when the request finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the image created from the response data. 90 | @param failure A block object to be executed when the request finishes unsuccessfully. This block has no return value and takes three arguments: the request object of the operation, the response for the request, and the error associated with the cause for the unsuccessful operation. 91 | 92 | @return A new image request operation 93 | */ 94 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 95 | + (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 96 | imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock 97 | cacheName:(NSString *)cacheNameOrNil 98 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 99 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 100 | #elif __MAC_OS_X_VERSION_MIN_REQUIRED 101 | + (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest 102 | imageProcessingBlock:(NSImage *(^)(NSImage *))imageProcessingBlock 103 | cacheName:(NSString *)cacheNameOrNil 104 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success 105 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 106 | #endif 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFJSONRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFJSONRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFHTTPRequestOperation.h" 25 | 26 | /** 27 | `AFJSONRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with JSON response data. 28 | 29 | ## Acceptable Content Types 30 | 31 | By default, `AFJSONRequestOperation` accepts the following MIME types, which includes the official standard, `application/json`, as well as other commonly-used types: 32 | 33 | - `application/json` 34 | - `text/json` 35 | */ 36 | @interface AFJSONRequestOperation : AFHTTPRequestOperation { 37 | @private 38 | id _responseJSON; 39 | NSError *_JSONError; 40 | } 41 | 42 | ///---------------------------- 43 | /// @name Getting Response Data 44 | ///---------------------------- 45 | 46 | /** 47 | A JSON object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error. 48 | */ 49 | @property (readonly, nonatomic, retain) id responseJSON; 50 | 51 | ///---------------------------------- 52 | /// @name Creating Request Operations 53 | ///---------------------------------- 54 | 55 | /** 56 | Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks. 57 | 58 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 59 | @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the JSON object created from the response data of request. 60 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as JSON. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. 61 | 62 | @return A new JSON request operation 63 | */ 64 | + (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest 65 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success 66 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 67 | @end 68 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFJSONRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFJSONRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFJSONRequestOperation.h" 24 | 25 | #include 26 | 27 | #import "JSONKit.h" 28 | 29 | static dispatch_queue_t af_json_request_operation_processing_queue; 30 | static dispatch_queue_t json_request_operation_processing_queue() { 31 | if (af_json_request_operation_processing_queue == NULL) { 32 | af_json_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.json-request.processing", 0); 33 | } 34 | 35 | return af_json_request_operation_processing_queue; 36 | } 37 | 38 | @interface AFJSONRequestOperation () 39 | @property (readwrite, nonatomic, retain) id responseJSON; 40 | @property (readwrite, nonatomic, retain) NSError *JSONError; 41 | 42 | + (NSSet *)defaultAcceptableContentTypes; 43 | + (NSSet *)defaultAcceptablePathExtensions; 44 | @end 45 | 46 | @implementation AFJSONRequestOperation 47 | @synthesize responseJSON = _responseJSON; 48 | @synthesize JSONError = _JSONError; 49 | 50 | + (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlRequest 51 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success 52 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 53 | { 54 | AFJSONRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; 55 | operation.completionBlock = ^ { 56 | if ([operation isCancelled]) { 57 | return; 58 | } 59 | 60 | if (operation.error) { 61 | if (failure) { 62 | dispatch_async(dispatch_get_main_queue(), ^(void) { 63 | failure(operation.request, operation.response, operation.error); 64 | }); 65 | } 66 | } else { 67 | dispatch_async(json_request_operation_processing_queue(), ^(void) { 68 | id JSON = operation.responseJSON; 69 | 70 | dispatch_async(dispatch_get_main_queue(), ^(void) { 71 | if (operation.error) { 72 | if (failure) { 73 | failure(operation.request, operation.response, operation.error); 74 | } 75 | } else { 76 | if (success) { 77 | success(operation.request, operation.response, JSON); 78 | } 79 | } 80 | }); 81 | }); 82 | } 83 | }; 84 | 85 | return operation; 86 | } 87 | 88 | + (NSSet *)defaultAcceptableContentTypes { 89 | return [NSSet setWithObjects:@"application/json", @"text/json", nil]; 90 | } 91 | 92 | + (NSSet *)defaultAcceptablePathExtensions { 93 | return [NSSet setWithObjects:@"json", nil]; 94 | } 95 | 96 | - (id)initWithRequest:(NSURLRequest *)urlRequest { 97 | self = [super initWithRequest:urlRequest]; 98 | if (!self) { 99 | return nil; 100 | } 101 | 102 | self.acceptableContentTypes = [[self class] defaultAcceptableContentTypes]; 103 | 104 | return self; 105 | } 106 | 107 | - (void)dealloc { 108 | [_responseJSON release]; 109 | [_JSONError release]; 110 | [super dealloc]; 111 | } 112 | 113 | - (id)responseJSON { 114 | if (!_responseJSON && [self isFinished]) { 115 | NSError *error = nil; 116 | 117 | if ([self.responseData length] == 0) { 118 | self.responseJSON = nil; 119 | } else { 120 | 121 | #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6 122 | if ([NSJSONSerialization class]) { 123 | self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error]; 124 | } else { 125 | self.responseJSON = [[JSONDecoder decoder] objectWithData:self.responseData error:&error]; 126 | } 127 | #else 128 | self.responseJSON = [[JSONDecoder decoder] objectWithData:self.responseData error:&error]; 129 | #endif 130 | } 131 | 132 | self.JSONError = error; 133 | } 134 | 135 | return _responseJSON; 136 | } 137 | 138 | - (NSError *)error { 139 | if (_JSONError) { 140 | return _JSONError; 141 | } else { 142 | return [super error]; 143 | } 144 | } 145 | 146 | #pragma mark - AFHTTPClientOperation 147 | 148 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 149 | return [[self defaultAcceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; 150 | } 151 | 152 | + (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest 153 | success:(void (^)(id object))success 154 | failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure 155 | { 156 | return [self JSONRequestOperationWithRequest:urlRequest success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, id JSON) { 157 | success(JSON); 158 | } failure:^(NSURLRequest __unused *request, NSHTTPURLResponse *response, NSError *error) { 159 | failure(response, error); 160 | }]; 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFNetworkActivityIndicatorManager.h: -------------------------------------------------------------------------------- 1 | // AFNetworkActivityIndicatorManager.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | 25 | #import 26 | 27 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 28 | #import 29 | 30 | /** 31 | `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero. 32 | */ 33 | @interface AFNetworkActivityIndicatorManager : NSObject { 34 | @private 35 | NSInteger _activityCount; 36 | BOOL _enabled; 37 | NSTimer *_activityIndicatorVisibilityTimer; 38 | } 39 | 40 | /** 41 | A Boolean value indicating whether the manager is enabled. 42 | 43 | @discussion If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO. 44 | */ 45 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled; 46 | 47 | /** 48 | Returns the shared network activity indicator manager object for the system. 49 | 50 | @return The systemwide network activity indicator manager. 51 | */ 52 | + (AFNetworkActivityIndicatorManager *)sharedManager; 53 | 54 | /** 55 | Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator. 56 | */ 57 | - (void)incrementActivityCount; 58 | 59 | /** 60 | Decrements the number of active network requests. If this number becomes zero before decrementing, this will stop animating the status bar network activity indicator. 61 | */ 62 | - (void)decrementActivityCount; 63 | 64 | @end 65 | #endif 66 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFNetworkActivityIndicatorManager.m: -------------------------------------------------------------------------------- 1 | // AFNetworkActivityIndicatorManager.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFNetworkActivityIndicatorManager.h" 24 | 25 | #import "AFHTTPRequestOperation.h" 26 | 27 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 28 | static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; 29 | 30 | @interface AFNetworkActivityIndicatorManager () 31 | @property (readwrite, nonatomic, assign) NSInteger activityCount; 32 | @property (readwrite, nonatomic, retain) NSTimer *activityIndicatorVisibilityTimer; 33 | @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; 34 | 35 | - (void)updateNetworkActivityIndicatorVisibility; 36 | @end 37 | 38 | @implementation AFNetworkActivityIndicatorManager 39 | @synthesize activityCount = _activityCount; 40 | @synthesize activityIndicatorVisibilityTimer = _activityIndicatorVisibilityTimer; 41 | @synthesize enabled = _enabled; 42 | @dynamic networkActivityIndicatorVisible; 43 | 44 | + (AFNetworkActivityIndicatorManager *)sharedManager { 45 | static AFNetworkActivityIndicatorManager *_sharedManager = nil; 46 | static dispatch_once_t oncePredicate; 47 | dispatch_once(&oncePredicate, ^{ 48 | _sharedManager = [[self alloc] init]; 49 | }); 50 | 51 | return _sharedManager; 52 | } 53 | 54 | - (id)init { 55 | self = [super init]; 56 | if (!self) { 57 | return nil; 58 | } 59 | 60 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incrementActivityCount) name:AFNetworkingOperationDidStartNotification object:nil]; 61 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(decrementActivityCount) name:AFNetworkingOperationDidFinishNotification object:nil]; 62 | 63 | return self; 64 | } 65 | 66 | - (void)dealloc { 67 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 68 | 69 | [_activityIndicatorVisibilityTimer invalidate]; 70 | [_activityIndicatorVisibilityTimer release]; _activityIndicatorVisibilityTimer = nil; 71 | 72 | [super dealloc]; 73 | } 74 | 75 | - (void)setActivityCount:(NSInteger)activityCount { 76 | [self willChangeValueForKey:@"activityCount"]; 77 | _activityCount = MAX(activityCount, 0); 78 | [self didChangeValueForKey:@"activityCount"]; 79 | 80 | if (self.enabled) { 81 | // Delay hiding of activity indicator for a short interval, to avoid flickering 82 | if (![self isNetworkActivityIndicatorVisible]) { 83 | [self.activityIndicatorVisibilityTimer invalidate]; 84 | self.activityIndicatorVisibilityTimer = [NSTimer timerWithTimeInterval:kAFNetworkActivityIndicatorInvisibilityDelay target:self selector:@selector(updateNetworkActivityIndicatorVisibility) userInfo:nil repeats:NO]; 85 | [[NSRunLoop currentRunLoop] addTimer:self.activityIndicatorVisibilityTimer forMode:NSRunLoopCommonModes]; 86 | } else { 87 | [self updateNetworkActivityIndicatorVisibility]; 88 | } 89 | } 90 | } 91 | 92 | - (BOOL)isNetworkActivityIndicatorVisible { 93 | return self.activityCount > 0; 94 | } 95 | 96 | - (void)updateNetworkActivityIndicatorVisibility { 97 | [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; 98 | } 99 | 100 | - (void)incrementActivityCount { 101 | @synchronized(self) { 102 | self.activityCount += 1; 103 | } 104 | } 105 | 106 | - (void)decrementActivityCount { 107 | @synchronized(self) { 108 | self.activityCount -= 1; 109 | } 110 | } 111 | 112 | @end 113 | #endif 114 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFNetworking.h: -------------------------------------------------------------------------------- 1 | // AFNetworking.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import 25 | 26 | #ifndef _AFNETWORKING_ 27 | #define _AFNETWORKING_ 28 | 29 | #import 30 | 31 | #import 32 | #import 33 | #import 34 | #import 35 | #import 36 | 37 | #import 38 | #import 39 | 40 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 41 | #import 42 | #import 43 | #endif 44 | 45 | #endif /* _AFNETWORKING_ */ -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFPropertyListRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFPropertyListRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFHTTPRequestOperation.h" 25 | 26 | /** 27 | `AFPropertyListRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and deserializing objects with property list (plist) response data. 28 | 29 | ## Acceptable Content Types 30 | 31 | By default, `AFPropertyListRequestOperation` accepts the following MIME types: 32 | 33 | - `application/x-plist` 34 | */ 35 | @interface AFPropertyListRequestOperation : AFHTTPRequestOperation { 36 | @private 37 | id _responsePropertyList; 38 | NSPropertyListFormat _propertyListFormat; 39 | NSPropertyListReadOptions _propertyListReadOptions; 40 | NSError *_propertyListError; 41 | } 42 | 43 | ///---------------------------- 44 | /// @name Getting Response Data 45 | ///---------------------------- 46 | 47 | /** 48 | An object deserialized from a plist constructed using the response data. 49 | */ 50 | @property (readonly, nonatomic, retain) id responsePropertyList; 51 | 52 | ///-------------------------------------- 53 | /// @name Managing Property List Behavior 54 | ///-------------------------------------- 55 | 56 | /** 57 | One of the `NSPropertyListMutabilityOptions` options, specifying the mutability of objects deserialized from the property list. By default, this is `NSPropertyListImmutable`. 58 | */ 59 | @property (nonatomic, assign) NSPropertyListReadOptions propertyListReadOptions; 60 | 61 | /** 62 | Creates and returns an `AFPropertyListRequestOperation` object and sets the specified success and failure callbacks. 63 | 64 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 65 | @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the object deserialized from a plist constructed using the response data. 66 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while deserializing the object from a property list. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. 67 | 68 | @return A new property list request operation 69 | */ 70 | + (AFPropertyListRequestOperation *)propertyListRequestOperationWithRequest:(NSURLRequest *)request 71 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success 72 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFPropertyListRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFPropertyListRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFPropertyListRequestOperation.h" 24 | 25 | static dispatch_queue_t af_property_list_request_operation_processing_queue; 26 | static dispatch_queue_t property_list_request_operation_processing_queue() { 27 | if (af_property_list_request_operation_processing_queue == NULL) { 28 | af_property_list_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.property-list-request.processing", 0); 29 | } 30 | 31 | return af_property_list_request_operation_processing_queue; 32 | } 33 | 34 | @interface AFPropertyListRequestOperation () 35 | @property (readwrite, nonatomic, retain) id responsePropertyList; 36 | @property (readwrite, nonatomic, assign) NSPropertyListFormat propertyListFormat; 37 | @property (readwrite, nonatomic, retain) NSError *error; 38 | 39 | + (NSSet *)defaultAcceptableContentTypes; 40 | + (NSSet *)defaultAcceptablePathExtensions; 41 | @end 42 | 43 | @implementation AFPropertyListRequestOperation 44 | @synthesize responsePropertyList = _responsePropertyList; 45 | @synthesize propertyListReadOptions = _propertyListReadOptions; 46 | @synthesize propertyListFormat = _propertyListFormat; 47 | @synthesize error = _propertyListError; 48 | 49 | + (AFPropertyListRequestOperation *)propertyListRequestOperationWithRequest:(NSURLRequest *)request 50 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success 51 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 52 | { 53 | AFPropertyListRequestOperation *operation = [[[self alloc] initWithRequest:request] autorelease]; 54 | operation.completionBlock = ^ { 55 | if ([operation isCancelled]) { 56 | return; 57 | } 58 | 59 | if (operation.error) { 60 | if (failure) { 61 | dispatch_async(dispatch_get_main_queue(), ^(void) { 62 | failure(operation.request, operation.response, operation.error); 63 | }); 64 | } 65 | } else { 66 | dispatch_async(property_list_request_operation_processing_queue(), ^(void) { 67 | id propertyList = operation.responsePropertyList; 68 | 69 | dispatch_async(dispatch_get_main_queue(), ^(void) { 70 | if (operation.error) { 71 | if (failure) { 72 | failure(operation.request, operation.response, operation.error); 73 | } 74 | } else { 75 | if (success) { 76 | success(operation.request, operation.response, propertyList); 77 | } 78 | } 79 | }); 80 | }); 81 | } 82 | }; 83 | 84 | return operation; 85 | } 86 | 87 | + (NSSet *)defaultAcceptableContentTypes { 88 | return [NSSet setWithObjects:@"application/x-plist", nil]; 89 | } 90 | 91 | + (NSSet *)defaultAcceptablePathExtensions { 92 | return [NSSet setWithObjects:@"plist", nil]; 93 | } 94 | 95 | - (id)initWithRequest:(NSURLRequest *)urlRequest { 96 | self = [super initWithRequest:urlRequest]; 97 | if (!self) { 98 | return nil; 99 | } 100 | 101 | self.acceptableContentTypes = [[self class] defaultAcceptableContentTypes]; 102 | 103 | self.propertyListReadOptions = NSPropertyListImmutable; 104 | 105 | return self; 106 | } 107 | 108 | - (void)dealloc { 109 | [_responsePropertyList release]; 110 | [_propertyListError release]; 111 | [super dealloc]; 112 | } 113 | 114 | - (id)responsePropertyList { 115 | if (!_responsePropertyList && [self isFinished]) { 116 | NSPropertyListFormat format; 117 | NSError *error = nil; 118 | self.responsePropertyList = [NSPropertyListSerialization propertyListWithData:self.responseData options:self.propertyListReadOptions format:&format error:&error]; 119 | self.propertyListFormat = format; 120 | self.error = error; 121 | } 122 | 123 | return _responsePropertyList; 124 | } 125 | 126 | #pragma mark - AFHTTPClientOperation 127 | 128 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 129 | return [[self defaultAcceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; 130 | } 131 | 132 | + (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest 133 | success:(void (^)(id object))success 134 | failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure 135 | { 136 | return [self propertyListRequestOperationWithRequest:urlRequest success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, id propertyList) { 137 | success(propertyList); 138 | } failure:^(NSURLRequest __unused *request, NSHTTPURLResponse *response, NSError *error) { 139 | failure(response, error); 140 | }]; 141 | } 142 | 143 | @end 144 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFXMLRequestOperation.h: -------------------------------------------------------------------------------- 1 | // AFXMLRequestOperation.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFHTTPRequestOperation.h" 25 | 26 | #import 27 | 28 | /** 29 | `AFXMLRequestOperation` is a subclass of `AFHTTPRequestOperation` for downloading and working with XML response data. 30 | 31 | ## Acceptable Content Types 32 | 33 | By default, `AFXMLRequestOperation` accepts the following MIME types, which includes the official standard, `application/xml`, as well as other commonly-used types: 34 | 35 | - `application/xml` 36 | - `text/xml` 37 | */ 38 | @interface AFXMLRequestOperation : AFHTTPRequestOperation { 39 | @private 40 | NSXMLParser *_responseXMLParser; 41 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 42 | NSXMLDocument *_responseXMLDocument; 43 | #endif 44 | NSError *_XMLError; 45 | } 46 | 47 | ///---------------------------- 48 | /// @name Getting Response Data 49 | ///---------------------------- 50 | 51 | /** 52 | An `NSXMLParser` object constructed from the response data. 53 | */ 54 | @property (readonly, nonatomic, retain) NSXMLParser *responseXMLParser; 55 | 56 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 57 | /** 58 | An `NSXMLDocument` object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error. 59 | */ 60 | @property (readonly, nonatomic, retain) NSXMLDocument *responseXMLDocument; 61 | #endif 62 | 63 | /** 64 | Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks. 65 | 66 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 67 | @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the XML parser constructed with the response data of request. 68 | @param failure A block object to be executed when the operation finishes unsuccessfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network error that occurred. 69 | 70 | @return A new XML request operation 71 | */ 72 | + (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest 73 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success 74 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 75 | 76 | 77 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 78 | /** 79 | Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks. 80 | 81 | @param urlRequest The request object to be loaded asynchronously during execution of the operation 82 | @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the XML document created from the response data of request. 83 | @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as XML. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. 84 | 85 | @return A new XML request operation 86 | */ 87 | + (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest 88 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success 89 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 90 | #endif 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/AFXMLRequestOperation.m: -------------------------------------------------------------------------------- 1 | // AFXMLRequestOperation.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import "AFXMLRequestOperation.h" 24 | 25 | #include 26 | 27 | static dispatch_queue_t af_xml_request_operation_processing_queue; 28 | static dispatch_queue_t xml_request_operation_processing_queue() { 29 | if (af_xml_request_operation_processing_queue == NULL) { 30 | af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", 0); 31 | } 32 | 33 | return af_xml_request_operation_processing_queue; 34 | } 35 | 36 | @interface AFXMLRequestOperation () 37 | @property (readwrite, nonatomic, retain) NSXMLParser *responseXMLParser; 38 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 39 | @property (readwrite, nonatomic, retain) NSXMLDocument *responseXMLDocument; 40 | #endif 41 | @property (readwrite, nonatomic, retain) NSError *error; 42 | 43 | + (NSSet *)defaultAcceptableContentTypes; 44 | + (NSSet *)defaultAcceptablePathExtensions; 45 | @end 46 | 47 | @implementation AFXMLRequestOperation 48 | @synthesize responseXMLParser = _responseXMLParser; 49 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 50 | @synthesize responseXMLDocument = _responseXMLDocument; 51 | #endif 52 | @synthesize error = _XMLError; 53 | 54 | + (AFXMLRequestOperation *)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest 55 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success 56 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 57 | { 58 | AFXMLRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; 59 | operation.completionBlock = ^ { 60 | if ([operation isCancelled]) { 61 | return; 62 | } 63 | 64 | if (operation.error) { 65 | if (failure) { 66 | dispatch_async(dispatch_get_main_queue(), ^(void) { 67 | failure(operation.request, operation.response, operation.error); 68 | }); 69 | } 70 | } else { 71 | NSXMLParser *XMLParser = operation.responseXMLParser; 72 | if (success) { 73 | dispatch_async(dispatch_get_main_queue(), ^(void) { 74 | success(operation.request, operation.response, XMLParser); 75 | }); 76 | } 77 | } 78 | }; 79 | 80 | return operation; 81 | } 82 | 83 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 84 | + (AFXMLRequestOperation *)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest 85 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success 86 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 87 | { 88 | AFXMLRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; 89 | operation.completionBlock = ^ { 90 | if ([operation isCancelled]) { 91 | return; 92 | } 93 | 94 | if (operation.error) { 95 | if (failure) { 96 | dispatch_async(dispatch_get_main_queue(), ^(void) { 97 | failure(operation.request, operation.response, operation.error); 98 | }); 99 | } 100 | } else { 101 | dispatch_async(xml_request_operation_processing_queue(), ^(void) { 102 | NSXMLDocument *XMLDocument = operation.responseXMLDocument; 103 | if (success) { 104 | dispatch_async(dispatch_get_main_queue(), ^(void) { 105 | success(operation.request, operation.response, XMLDocument); 106 | }); 107 | } 108 | }); 109 | } 110 | }; 111 | 112 | return operation; 113 | } 114 | #endif 115 | 116 | + (NSSet *)defaultAcceptableContentTypes { 117 | return [NSSet setWithObjects:@"application/xml", @"text/xml", nil]; 118 | } 119 | 120 | + (NSSet *)defaultAcceptablePathExtensions { 121 | return [NSSet setWithObjects:@"xml", nil]; 122 | } 123 | 124 | - (id)initWithRequest:(NSURLRequest *)urlRequest { 125 | self = [super initWithRequest:urlRequest]; 126 | if (!self) { 127 | return nil; 128 | } 129 | 130 | self.acceptableContentTypes = [[self class] defaultAcceptableContentTypes]; 131 | 132 | return self; 133 | } 134 | 135 | - (void)dealloc { 136 | _responseXMLParser.delegate = nil; 137 | [_responseXMLParser release]; 138 | 139 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 140 | [_responseXMLDocument release]; 141 | #endif 142 | 143 | [_XMLError release]; 144 | 145 | [super dealloc]; 146 | } 147 | 148 | - (NSXMLParser *)responseXMLParser { 149 | if (!_responseXMLParser && [self isFinished]) { 150 | self.responseXMLParser = [[[NSXMLParser alloc] initWithData:self.responseData] autorelease]; 151 | } 152 | 153 | return _responseXMLParser; 154 | } 155 | 156 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 157 | - (NSXMLDocument *)responseXMLDocument { 158 | if (!_responseXMLDocument && [self isFinished]) { 159 | NSError *error = nil; 160 | self.responseXMLDocument = [[[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error] autorelease]; 161 | self.error = error; 162 | } 163 | 164 | return _responseXMLDocument; 165 | } 166 | #endif 167 | 168 | #pragma mark - NSOperation 169 | 170 | - (void)cancel { 171 | [super cancel]; 172 | 173 | self.responseXMLParser.delegate = nil; 174 | } 175 | 176 | #pragma mark - AFHTTPClientOperation 177 | 178 | + (BOOL)canProcessRequest:(NSURLRequest *)request { 179 | return [[self defaultAcceptableContentTypes] containsObject:[request valueForHTTPHeaderField:@"Accept"]] || [[self defaultAcceptablePathExtensions] containsObject:[[request URL] pathExtension]]; 180 | } 181 | 182 | + (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest 183 | success:(void (^)(id object))success 184 | failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure 185 | { 186 | #if __MAC_OS_X_VERSION_MIN_REQUIRED 187 | return [self XMLDocumentRequestOperationWithRequest:urlRequest success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSXMLDocument *XMLDocument) { 188 | success(XMLDocument); 189 | } failure:^(NSURLRequest __unused *request, NSHTTPURLResponse *response, NSError *error) { 190 | failure(response, error); 191 | }]; 192 | #else 193 | return [self XMLParserRequestOperationWithRequest:urlRequest success:^(NSURLRequest __unused *request, NSHTTPURLResponse __unused *response, NSXMLParser *XMLParser) { 194 | success(XMLParser); 195 | } failure:^(NSURLRequest __unused *request, NSHTTPURLResponse *response, NSError *error) { 196 | failure(response, error); 197 | }]; 198 | #endif 199 | } 200 | 201 | @end 202 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/UIImageView+AFNetworking.h: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.h 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import "AFImageRequestOperation.h" 25 | 26 | #import 27 | 28 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 29 | #import 30 | 31 | /** 32 | This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL. 33 | */ 34 | @interface UIImageView (AFNetworking) 35 | 36 | /** 37 | Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL, and sets it the request is finished. If the image is cached locally, the image is set immediately, otherwise, the image is set once the request is finished. 38 | 39 | @discussion By default, url requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set to use HTTP pipelining, and not handle cookies. To configure url requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:` 40 | 41 | @param url The URL used for the image request. 42 | */ 43 | - (void)setImageWithURL:(NSURL *)url; 44 | 45 | /** 46 | Creates and enqueues an image request operation, which asynchronously downloads the image from the specified URL. If the image is cached locally, the image is set immediately. Otherwise, the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished. 47 | 48 | @param url The URL used for the image request. 49 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes. 50 | 51 | @discussion By default, url requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set to use HTTP pipelining, and not handle cookies. To configure url requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:` 52 | */ 53 | - (void)setImageWithURL:(NSURL *)url 54 | placeholderImage:(UIImage *)placeholderImage; 55 | 56 | /** 57 | Creates and enqueues an image request operation, which asynchronously downloads the image with the specified url request object. If the image is cached locally, the image is set immediately. Otherwise, the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished. 58 | 59 | @param urlRequest The url request used for the image request. 60 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes. 61 | @param success A block to be executed when the image request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the request and response parameters will be `nil`. 62 | @param failure A block object to be executed when the image request operation finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred. 63 | 64 | @discussion By default, url requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set to use HTTP pipelining, and not handle cookies. To configure url requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:` 65 | */ 66 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 67 | placeholderImage:(UIImage *)placeholderImage 68 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 69 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; 70 | 71 | - (void)cancelImageRequestOperation; 72 | 73 | @end 74 | #endif 75 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFNetworking/UIImageView+AFNetworking.m: -------------------------------------------------------------------------------- 1 | // UIImageView+AFNetworking.m 2 | // 3 | // Copyright (c) 2011 Gowalla (http://gowalla.com/) 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | #import 24 | #import 25 | 26 | #if __IPHONE_OS_VERSION_MIN_REQUIRED 27 | 28 | #import "UIImageView+AFNetworking.h" 29 | 30 | #import "AFImageCache.h" 31 | 32 | static char kAFImageRequestOperationObjectKey; 33 | 34 | @interface UIImageView (_AFNetworking) 35 | @property (readwrite, nonatomic, retain, setter = af_setImageRequestOperation:) AFImageRequestOperation *af_imageRequestOperation; 36 | @end 37 | 38 | @implementation UIImageView (_AFNetworking) 39 | @dynamic af_imageRequestOperation; 40 | @end 41 | 42 | #pragma mark - 43 | 44 | @implementation UIImageView (AFNetworking) 45 | 46 | - (AFHTTPRequestOperation *)af_imageRequestOperation { 47 | return (AFHTTPRequestOperation *)objc_getAssociatedObject(self, &kAFImageRequestOperationObjectKey); 48 | } 49 | 50 | - (void)af_setImageRequestOperation:(AFImageRequestOperation *)imageRequestOperation { 51 | objc_setAssociatedObject(self, &kAFImageRequestOperationObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 52 | } 53 | 54 | + (NSOperationQueue *)af_sharedImageRequestOperationQueue { 55 | static NSOperationQueue *_imageRequestOperationQueue = nil; 56 | 57 | if (!_imageRequestOperationQueue) { 58 | _imageRequestOperationQueue = [[NSOperationQueue alloc] init]; 59 | [_imageRequestOperationQueue setMaxConcurrentOperationCount:8]; 60 | } 61 | 62 | return _imageRequestOperationQueue; 63 | } 64 | 65 | #pragma mark - 66 | 67 | - (void)setImageWithURL:(NSURL *)url { 68 | [self setImageWithURL:url placeholderImage:nil]; 69 | } 70 | 71 | - (void)setImageWithURL:(NSURL *)url 72 | placeholderImage:(UIImage *)placeholderImage 73 | { 74 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:30.0]; 75 | [request setHTTPShouldHandleCookies:NO]; 76 | [request setHTTPShouldUsePipelining:YES]; 77 | 78 | [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil]; 79 | } 80 | 81 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest 82 | placeholderImage:(UIImage *)placeholderImage 83 | success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success 84 | failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure 85 | { 86 | if (![urlRequest URL] || (![self.af_imageRequestOperation isCancelled] && [[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]])) { 87 | return; 88 | } else { 89 | [self cancelImageRequestOperation]; 90 | } 91 | 92 | UIImage *cachedImage = [[AFImageCache sharedImageCache] cachedImageForURL:[urlRequest URL] cacheName:nil]; 93 | if (cachedImage) { 94 | self.image = cachedImage; 95 | self.af_imageRequestOperation = nil; 96 | 97 | if (success) { 98 | success(nil, nil, cachedImage); 99 | } 100 | } else { 101 | self.image = placeholderImage; 102 | 103 | self.af_imageRequestOperation = [AFImageRequestOperation imageRequestOperationWithRequest:urlRequest imageProcessingBlock:nil cacheName:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { 104 | if (self.af_imageRequestOperation && ![self.af_imageRequestOperation isCancelled]) { 105 | if (success) { 106 | success(request, response, image); 107 | } 108 | 109 | if ([[request URL] isEqual:[[self.af_imageRequestOperation request] URL]]) { 110 | self.image = image; 111 | } else { 112 | self.image = placeholderImage; 113 | } 114 | } 115 | } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 116 | self.af_imageRequestOperation = nil; 117 | 118 | if (failure) { 119 | failure(request, response, error); 120 | } 121 | }]; 122 | 123 | [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation]; 124 | } 125 | } 126 | 127 | - (void)cancelImageRequestOperation { 128 | [self.af_imageRequestOperation cancel]; 129 | } 130 | 131 | @end 132 | #endif 133 | -------------------------------------------------------------------------------- /IOSBoilerplate/AFURLCache.h: -------------------------------------------------------------------------------- 1 | // AFURLCache.h 2 | // 3 | // Copyright (c) 2010-2011 Olivier Poitrey 4 | // Modernized to use GCD by Peter Steinberger 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is furnished 11 | // to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in all 14 | // copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #import 25 | 26 | @interface AFURLCache : NSURLCache { 27 | NSString *_diskCachePath; 28 | NSMutableDictionary *_diskCacheInfo; 29 | BOOL _diskCacheInfoDirty; 30 | BOOL _ignoreMemoryOnlyStoragePolicy; 31 | NSUInteger _diskCacheUsage; 32 | NSTimeInterval _minCacheInterval; 33 | dispatch_source_t _maintenanceTimer; 34 | BOOL _timerPaused; 35 | } 36 | 37 | /* 38 | * Defines the minimum number of seconds between now and the expiration time of a cacheable response 39 | * in order for the response to be cached on disk. This prevent from spending time and storage capacity 40 | * for an entry which will certainly expire before behing read back from disk cache (memory cache is 41 | * best suited for short term cache). The default value is set to 5 minutes (300 seconds). 42 | */ 43 | @property (nonatomic, assign) NSTimeInterval minCacheInterval; 44 | 45 | /* 46 | * Allow the responses that have a storage policy of NSURLCacheStorageAllowedInMemoryOnly to be cached 47 | * on the disk anyway. 48 | * 49 | * This is mainly a workaround against cache policies generated by the UIWebViews: starting from iOS 4.2, 50 | * it always has a cache policy of NSURLCacheStorageAllowedInMemoryOnly. 51 | * The default value is YES 52 | */ 53 | @property (nonatomic, assign) BOOL ignoreMemoryOnlyStoragePolicy; 54 | 55 | /* 56 | * Returns a default cache director path to be used at cache initialization. The generated path directory 57 | * will be located in the application's cache directory and thus won't be synced by iTunes. 58 | */ 59 | + (NSString *)defaultCachePath; 60 | 61 | /* 62 | * Checks if the provided URL exists in cache. 63 | */ 64 | - (BOOL)isCached:(NSURL *)url; 65 | 66 | @end -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncCell.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "FastCell.h" 30 | 31 | @interface AsyncCell : FastCell 32 | 33 | @property (nonatomic, retain) NSDictionary* info; 34 | @property (nonatomic, retain) UIImage* image; 35 | 36 | - (void) updateCellInfo:(NSDictionary*)_info; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncCell.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "AsyncCell.h" 30 | #import "DictionaryHelper.h" 31 | 32 | #import "UIImageView+AFNetworking.h" 33 | 34 | @implementation AsyncCell 35 | 36 | @synthesize info; 37 | @synthesize image; 38 | 39 | - (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 40 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 41 | { 42 | self.backgroundColor = [UIColor whiteColor]; 43 | self.opaque = YES; 44 | } 45 | return self; 46 | } 47 | 48 | - (void) prepareForReuse { 49 | [super prepareForReuse]; 50 | self.image = nil; 51 | } 52 | 53 | static UIFont* system14 = nil; 54 | static UIFont* bold14 = nil; 55 | 56 | + (void)initialize 57 | { 58 | if(self == [AsyncCell class]) 59 | { 60 | system14 = [[UIFont systemFontOfSize:14] retain]; 61 | bold14 = [[UIFont boldSystemFontOfSize:14] retain]; 62 | } 63 | } 64 | 65 | - (void)dealloc { 66 | [info release]; 67 | [image release]; 68 | 69 | [super dealloc]; 70 | } 71 | 72 | - (void) drawContentView:(CGRect)rect { 73 | CGContextRef context = UIGraphicsGetCurrentContext(); 74 | 75 | [[UIColor whiteColor] set]; 76 | CGContextFillRect(context, rect); 77 | 78 | NSString* name = [info stringForKey:@"from_user"]; 79 | NSString* text = [info stringForKey:@"text"]; 80 | 81 | CGFloat widthr = self.frame.size.width - 70; 82 | 83 | [[UIColor blackColor] set]; 84 | [name drawInRect:CGRectMake(63.0, 5.0, widthr, 20.0) withFont:bold14 lineBreakMode:UILineBreakModeTailTruncation]; 85 | [[UIColor grayColor] set]; 86 | [text drawInRect:CGRectMake(63.0, 25.0, widthr, 20.0) withFont:system14 lineBreakMode:UILineBreakModeTailTruncation]; 87 | 88 | if (self.image) { 89 | CGRect r = CGRectMake(5.0, 5.0, 48.0, 48.0); 90 | [self.image drawInRect:r]; 91 | } 92 | } 93 | 94 | - (void) updateCellInfo:(NSDictionary*)_info { 95 | self.info = _info; 96 | NSString *urlString = [info stringForKey:@"profile_image_url"]; 97 | if (urlString) { 98 | AFImageRequestOperation *operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] success:^(UIImage *requestedImage) { 99 | self.image = requestedImage; 100 | [self setNeedsDisplay]; 101 | }]; 102 | [operation start]; 103 | } 104 | } 105 | 106 | @end 107 | -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncCellImagesExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncCellImagesExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface AsyncCellImagesExample : UIViewController 32 | 33 | @property (nonatomic, retain) IBOutlet UITableView* table; 34 | @property (nonatomic, retain) NSArray* results; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncCellImagesExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncCellImagesExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "AsyncCellImagesExample.h" 30 | #import "SVProgressHUD.h" 31 | #import "TwitterSearchClient.h" 32 | #import "AsyncCell.h" 33 | 34 | @implementation AsyncCellImagesExample 35 | 36 | @synthesize table; 37 | @synthesize results; 38 | 39 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 40 | { 41 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 42 | if (self) { 43 | // Custom initialization 44 | } 45 | return self; 46 | } 47 | 48 | - (void)didReceiveMemoryWarning 49 | { 50 | // Releases the view if it doesn't have a superview. 51 | [super didReceiveMemoryWarning]; 52 | 53 | // Release any cached data, images, etc that aren't in use. 54 | } 55 | 56 | #pragma mark - UITableViewDelegate and DataSource 57 | 58 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 59 | { 60 | return 1; 61 | } 62 | 63 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 64 | { 65 | return [results count]; 66 | } 67 | 68 | // Customize the appearance of table view cells. 69 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 70 | { 71 | static NSString *CellIdentifier = @"Cell"; 72 | 73 | AsyncCell *cell = (AsyncCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 74 | if (cell == nil) { 75 | cell = [[[AsyncCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 76 | } 77 | 78 | NSDictionary* obj = [results objectAtIndex:indexPath.row]; 79 | [cell updateCellInfo:obj]; 80 | return cell; 81 | } 82 | 83 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 84 | return 58; 85 | } 86 | 87 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 88 | { 89 | } 90 | 91 | #pragma mark - View lifecycle 92 | 93 | - (void)viewDidLoad 94 | { 95 | [super viewDidLoad]; 96 | self.title = @"Latest twits about #iOS"; 97 | } 98 | 99 | - (void)viewDidUnload 100 | { 101 | [super viewDidUnload]; 102 | // Release any retained subviews of the main view. 103 | // e.g. self.myOutlet = nil; 104 | } 105 | 106 | - (void)viewDidAppear:(BOOL)animated { 107 | [super viewDidAppear:animated]; 108 | } 109 | 110 | - (void)viewWillAppear:(BOOL)animated { 111 | [super viewWillAppear:animated]; 112 | 113 | [SVProgressHUD showInView:self.view]; 114 | 115 | [[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"iOS" forKey:@"q"] success:^(id object) { 116 | [SVProgressHUD dismiss]; 117 | 118 | self.results = [object valueForKey:@"results"]; 119 | [table reloadData]; 120 | } failure:^(NSHTTPURLResponse *response, NSError *error) { 121 | [SVProgressHUD dismissWithError:[error localizedDescription]]; 122 | }]; 123 | } 124 | 125 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 126 | return YES; 127 | } 128 | 129 | - (void)dealloc { 130 | [table release]; 131 | [results release]; 132 | 133 | [super dealloc]; 134 | } 135 | 136 | @end 137 | -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncImageExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncImageExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface AsyncImageExample : UIViewController 32 | 33 | @property (nonatomic, retain) IBOutlet UIImageView* imageView; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /IOSBoilerplate/AsyncImageExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // AsyncImageExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "AsyncImageExample.h" 30 | 31 | #import "UIImageView+AFNetworking.h" 32 | 33 | @implementation AsyncImageExample 34 | 35 | @synthesize imageView; 36 | 37 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 38 | { 39 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 40 | if (self) { 41 | // Custom initialization 42 | } 43 | return self; 44 | } 45 | 46 | - (void)didReceiveMemoryWarning 47 | { 48 | // Releases the view if it doesn't have a superview. 49 | [super didReceiveMemoryWarning]; 50 | 51 | // Release any cached data, images, etc that aren't in use. 52 | } 53 | 54 | #pragma mark - View lifecycle 55 | 56 | - (void)viewDidLoad 57 | { 58 | [super viewDidLoad]; 59 | self.title = @"Async image example"; 60 | } 61 | 62 | - (void)viewDidUnload 63 | { 64 | [super viewDidUnload]; 65 | // Release any retained subviews of the main view. 66 | // e.g. self.myOutlet = nil; 67 | } 68 | 69 | - (void)viewWillAppear:(BOOL)animated { 70 | [super viewWillAppear:animated]; 71 | 72 | [self.imageView setImageWithURL:[NSURL URLWithString:@"http://upload.wikimedia.org/wikipedia/commons/thumb/e/ef/Zaragoza_shel.JPG/266px-Zaragoza_shel.JPG"]]; 73 | } 74 | 75 | - (void)viewDidAppear:(BOOL)animated { 76 | [super viewDidAppear:animated]; 77 | } 78 | 79 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 80 | return YES; 81 | } 82 | 83 | - (void)dealloc { 84 | [imageView release]; 85 | 86 | [super dealloc]; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /IOSBoilerplate/AutocompleteLocationExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // AutocompleteLocationExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface AutocompleteLocationExample : UIViewController 32 | 33 | @property (nonatomic, retain) NSMutableArray* suggestions; 34 | @property (nonatomic, retain) IBOutlet UILabel* label; 35 | @property (assign) BOOL dirty; 36 | @property (assign) BOOL loading; 37 | 38 | - (void) loadSearchSuggestions; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /IOSBoilerplate/AutocompleteLocationExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // AutocompleteLocationExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "AutocompleteLocationExample.h" 30 | #import "StringHelper.h" 31 | #import "JSONKit.h" 32 | #import "AFJSONRequestOperation.h" 33 | #import 34 | 35 | @implementation AutocompleteLocationExample 36 | 37 | @synthesize suggestions; 38 | @synthesize dirty; 39 | @synthesize loading; 40 | @synthesize label; 41 | 42 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 43 | { 44 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 45 | if (self) { 46 | // Custom initialization 47 | } 48 | return self; 49 | } 50 | 51 | - (void)didReceiveMemoryWarning 52 | { 53 | // Releases the view if it doesn't have a superview. 54 | [super didReceiveMemoryWarning]; 55 | 56 | // Release any cached data, images, etc that aren't in use. 57 | } 58 | 59 | #pragma mark - 60 | #pragma mark SearchBarDelegate 61 | 62 | - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 63 | { 64 | if ([searchText length] > 2) { 65 | if (loading) { 66 | dirty = YES; 67 | } else { 68 | [self loadSearchSuggestions]; 69 | } 70 | } 71 | } 72 | 73 | - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString 74 | { 75 | return NO; 76 | } 77 | 78 | 79 | #pragma mark - 80 | #pragma mark Search backend 81 | 82 | - (void) loadSearchSuggestions { 83 | loading = YES; 84 | NSString* query = self.searchDisplayController.searchBar.text; 85 | // You could limit the search to a region (e.g. a country) by appending more text to the query 86 | // example: query = [NSString stringWithFormat:@"%@, Spain", text]; 87 | NSString *urlEncode = [query urlEncode]; 88 | NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&hl=%@&oe=UTF8", urlEncode, [[NSLocale currentLocale] localeIdentifier]]; 89 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 90 | 91 | AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 92 | NSMutableArray* sug = [[NSMutableArray alloc] init]; 93 | 94 | NSArray* placemarks = [JSON objectForKey:@"Placemark"]; 95 | 96 | for (NSDictionary* placemark in placemarks) { 97 | NSString* address = [placemark objectForKey:@"address"]; 98 | 99 | NSDictionary* point = [placemark objectForKey:@"Point"]; 100 | NSArray* coordinates = [point objectForKey:@"coordinates"]; 101 | NSNumber* lon = [coordinates objectAtIndex:0]; 102 | NSNumber* lat = [coordinates objectAtIndex:1]; 103 | 104 | MKPointAnnotation* place = [[MKPointAnnotation alloc] init]; 105 | place.title = address; 106 | CLLocationCoordinate2D c = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]); 107 | place.coordinate = c; 108 | [sug addObject:place]; 109 | [place release]; 110 | } 111 | 112 | self.suggestions = sug; 113 | [sug release]; 114 | 115 | [self.searchDisplayController.searchResultsTableView reloadData]; 116 | loading = NO; 117 | 118 | if (dirty) { 119 | dirty = NO; 120 | [self loadSearchSuggestions]; 121 | } 122 | } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 123 | NSLog(@"failure %@", [error localizedDescription]); 124 | loading = NO; 125 | }]; 126 | operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil]; 127 | [operation start]; 128 | } 129 | 130 | #pragma mark - 131 | #pragma mark UITableView methods 132 | 133 | - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath 134 | { 135 | static NSString *cellIdentifier = @"suggest"; 136 | 137 | UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:cellIdentifier]; 138 | if (cell == nil) 139 | { 140 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 141 | cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 142 | cell.textLabel.numberOfLines = 0; 143 | cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:12.0]; 144 | } 145 | 146 | MKPointAnnotation* suggestion = [suggestions objectAtIndex:indexPath.row]; 147 | cell.textLabel.text = suggestion.title; 148 | return cell; 149 | } 150 | 151 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 152 | { 153 | [self.searchDisplayController setActive:NO animated:YES]; 154 | 155 | MKPointAnnotation* suggestion = [suggestions objectAtIndex:indexPath.row]; 156 | // You could add "suggestion" to a map since it implements MKAnnotation 157 | // example: [map addAnnotation:suggestion] 158 | 159 | label.text = suggestion.title; 160 | } 161 | 162 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 163 | return [suggestions count]; 164 | } 165 | 166 | #pragma mark - View lifecycle 167 | 168 | - (void)viewDidLoad 169 | { 170 | [super viewDidLoad]; 171 | self.title = @"Search a location"; 172 | } 173 | 174 | - (void)viewDidUnload 175 | { 176 | [super viewDidUnload]; 177 | // Release any retained subviews of the main view. 178 | // e.g. self.myOutlet = nil; 179 | } 180 | 181 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 182 | { 183 | return YES; 184 | } 185 | 186 | - (void)dealloc { 187 | [suggestions release]; 188 | [label release]; 189 | [super dealloc]; 190 | } 191 | 192 | @end 193 | -------------------------------------------------------------------------------- /IOSBoilerplate/BrowserSampleViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BrowserSampleViewController.h 3 | // 4 | // This software is licensed under the MIT Software License 5 | // 6 | // Copyright (c) 2011 Nathan Buggia 7 | // http://nathanbuggia.com/posts/browser-view-controller/ 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 10 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation 11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 12 | // to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 15 | // the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 18 | // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // Artwork generously contributed by Joseph Wain of http://glyphish.com (buy his Pro pack of icons!) 24 | // 25 | 26 | #import 27 | #import "BrowserViewController.h" 28 | 29 | #define DEMO_URL @"http://nytimes.com" 30 | 31 | @interface BrowserSampleViewController : UIViewController 32 | 33 | { 34 | IBOutlet UIWebView *webView; 35 | IBOutlet UIButton *button; 36 | IBOutlet UITextView *textView; 37 | } 38 | 39 | @property (nonatomic, retain) UIWebView *webView; 40 | @property (nonatomic, retain) UIButton *button; 41 | @property (nonatomic, retain) UITextView *textView; 42 | 43 | - (IBAction)openLinkInBrowser:(id)sender; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /IOSBoilerplate/BrowserSampleViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BrowserSampleViewController.m 3 | // 4 | // This software is licensed under the MIT Software License 5 | // 6 | // Copyright (c) 2011 Nathan Buggia 7 | // http://nathanbuggia.com/posts/browser-view-controller/ 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 10 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation 11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 12 | // to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 15 | // the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 18 | // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // Artwork generously contributed by Joseph Wain of http://glyphish.com (buy his Pro pack of icons!) 24 | // 25 | 26 | #import "BrowserSampleViewController.h" 27 | 28 | @implementation BrowserSampleViewController 29 | 30 | @synthesize webView; 31 | @synthesize button; 32 | @synthesize textView; 33 | 34 | - (void)openLinkInBrowser:(id)sender 35 | { 36 | NSURL *url = [NSURL URLWithString:DEMO_URL]; 37 | BrowserViewController *bvc = [[BrowserViewController alloc] initWithUrls:url]; 38 | [self.navigationController pushViewController:bvc animated:YES]; 39 | [bvc release]; 40 | } 41 | 42 | -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { 43 | if ( inType == UIWebViewNavigationTypeLinkClicked ) { 44 | [[UIApplication sharedApplication] openURL:[inRequest URL]]; 45 | return NO; 46 | } 47 | 48 | return YES; 49 | } 50 | 51 | - (void)viewDidLoad 52 | { 53 | [super viewDidLoad]; 54 | NSString* theHtml = [NSString stringWithFormat:@"%@", DEMO_URL, DEMO_URL]; 55 | self.navigationItem.title = @"Examples"; 56 | [webView loadHTMLString:theHtml baseURL:nil]; 57 | 58 | [button setTitle:DEMO_URL forState:UIControlStateNormal]; 59 | 60 | [textView setText:DEMO_URL]; 61 | } 62 | 63 | - (void)viewWillAppear:(BOOL)animated 64 | { 65 | [super viewWillAppear:animated]; 66 | } 67 | 68 | - (void)viewDidAppear:(BOOL)animated 69 | { 70 | [super viewDidAppear:animated]; 71 | } 72 | 73 | - (void)viewWillDisappear:(BOOL)animated 74 | { 75 | [super viewWillDisappear:animated]; 76 | } 77 | 78 | - (void)viewDidDisappear:(BOOL)animated 79 | { 80 | [super viewDidDisappear:animated]; 81 | } 82 | 83 | - (void)didReceiveMemoryWarning 84 | { 85 | // Releases the view if it doesn't have a superview. 86 | [super didReceiveMemoryWarning]; 87 | 88 | // Relinquish ownership any cached data, images, etc that aren't in use. 89 | } 90 | 91 | - (void)viewDidUnload 92 | { 93 | [super viewDidUnload]; 94 | 95 | // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 96 | // For example: self.myOutlet = nil; 97 | } 98 | 99 | - (void)dealloc 100 | { 101 | [super dealloc]; 102 | } 103 | 104 | @end 105 | -------------------------------------------------------------------------------- /IOSBoilerplate/BrowserViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BrowserViewController.h 3 | // 4 | // This software is licensed under the MIT Software License 5 | // 6 | // Copyright (c) 2011 Nathan Buggia 7 | // http://nathanbuggia.com/posts/browser-view-controller/ 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 10 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation 11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 12 | // to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 15 | // the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 18 | // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // Artwork generously contributed by Joseph Wain of http://glyphish.com (buy his Pro pack of icons!) 24 | // 25 | 26 | 27 | #import 28 | #import "MyApplication.h" 29 | 30 | // The names of the images for the 'back' and 'forward' buttons in the toolbar. 31 | #define PNG_BUTTON_FORWARD @"right.png" 32 | #define PNG_BUTTON_BACK @"left.png" 33 | 34 | // List of all strings used 35 | #define ACTION_CANCEL @"Cancel" 36 | #define ACTION_OPEN_IN_SAFARI @"Open in Safari" 37 | 38 | @interface BrowserViewController : UIViewController 39 | < 40 | UIWebViewDelegate, 41 | UIActionSheetDelegate 42 | > 43 | { 44 | // the current URL of the UIWebView 45 | NSURL *url; 46 | 47 | // the UIWebView where we render the contents of the URL 48 | IBOutlet UIWebView *webView; 49 | 50 | // the UIToolbar with the "back" "forward" "reload" and "action" buttons 51 | IBOutlet UIToolbar *toolbar; 52 | 53 | // used to indicate that we are downloading content from the web 54 | UIActivityIndicatorView *activityIndicator; 55 | 56 | // pointers to the buttons on the toolbar 57 | UIBarButtonItem *backButton; 58 | UIBarButtonItem *forwardButton; 59 | UIBarButtonItem *stopButton; 60 | UIBarButtonItem *reloadButton; 61 | UIBarButtonItem *actionButton; 62 | } 63 | 64 | @property(nonatomic, retain) NSURL *url; 65 | @property(nonatomic, retain) UIWebView *webView; 66 | @property(nonatomic, retain) UIToolbar *toolbar; 67 | @property(nonatomic, retain) UIBarButtonItem *backButton; 68 | @property(nonatomic, retain) UIBarButtonItem *forwardButton; 69 | @property(nonatomic, retain) UIBarButtonItem *stopButton; 70 | @property(nonatomic, retain) UIBarButtonItem *reloadButton; 71 | @property(nonatomic, retain) UIBarButtonItem *actionButton; 72 | 73 | // Initializes the BrowserViewController with a specific URL 74 | - (id)initWithUrls:(NSURL*)u; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /IOSBoilerplate/DataHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // DataHelper.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface NSData (helper) 32 | 33 | - (NSString*)hexString; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /IOSBoilerplate/DataHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // DataHelper.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "DataHelper.h" 30 | 31 | @implementation NSData (helper) 32 | 33 | - (NSString*)hexString { 34 | NSMutableString *str = [NSMutableString stringWithCapacity:64]; 35 | int length = [self length]; 36 | char *bytes = malloc(sizeof(char) * length); 37 | 38 | [self getBytes:bytes length:length]; 39 | 40 | int i = 0; 41 | 42 | for (; i < length; i++) { 43 | [str appendFormat:@"%02.2hhx", bytes[i]]; 44 | } 45 | free(bytes); 46 | 47 | return str; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /IOSBoilerplate/DictionaryHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // DictionaryHelper.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface NSDictionary (helper) 32 | 33 | - (NSString*) stringForKey:(id)key; 34 | 35 | - (NSNumber*) numberForKey:(id)key; 36 | 37 | - (NSMutableDictionary*) dictionaryForKey:(id)key; 38 | 39 | - (NSMutableArray*) arrayForKey:(id)key; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /IOSBoilerplate/DictionaryHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // DictionaryHelper.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "DictionaryHelper.h" 30 | 31 | @implementation NSDictionary (helper) 32 | 33 | - (NSString*) stringForKey:(id)key { 34 | id s = [self objectForKey:key]; 35 | if (s == [NSNull null] || ![s isKindOfClass:[NSString class]]) { 36 | return nil; 37 | } 38 | return s; 39 | } 40 | 41 | - (NSNumber*) numberForKey:(id)key { 42 | id s = [self objectForKey:key]; 43 | if (s == [NSNull null] || ![s isKindOfClass:[NSNumber class]]) { 44 | return nil; 45 | } 46 | return s; 47 | } 48 | 49 | - (NSMutableDictionary*) dictionaryForKey:(id)key { 50 | id s = [self objectForKey:key]; 51 | if (s == [NSNull null] || ![s isKindOfClass:[NSMutableDictionary class]]) { 52 | return nil; 53 | } 54 | return s; 55 | } 56 | 57 | - (NSMutableArray*) arrayForKey:(id)key { 58 | id s = [self objectForKey:key]; 59 | if (s == [NSNull null] || ![s isKindOfClass:[NSMutableArray class]]) { 60 | return nil; 61 | } 62 | return s; 63 | } 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /IOSBoilerplate/DirectionsExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // DirectionsExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface DirectionsExample : UIViewController 32 | 33 | @property(nonatomic, retain) id source; 34 | @property(nonatomic, retain) id destination; 35 | @property(nonatomic, retain) MKPolyline* routeLine; 36 | @property (nonatomic, retain) IBOutlet MKMapView* map; 37 | 38 | - (NSMutableArray *)decodePolyLine:(NSMutableString *)encoded; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /IOSBoilerplate/EGORefreshTableHeaderView.h: -------------------------------------------------------------------------------- 1 | // 2 | // EGORefreshTableHeaderView.h 3 | // Demo 4 | // 5 | // Created by Devin Doty on 10/14/09October14. 6 | // Copyright 2009 enormego. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | // 26 | 27 | #import 28 | #import 29 | 30 | typedef enum{ 31 | EGOOPullRefreshPulling = 0, 32 | EGOOPullRefreshNormal, 33 | EGOOPullRefreshLoading, 34 | } EGOPullRefreshState; 35 | 36 | @protocol EGORefreshTableHeaderDelegate; 37 | @interface EGORefreshTableHeaderView : UIView { 38 | 39 | id _delegate; 40 | EGOPullRefreshState _state; 41 | 42 | UILabel *_lastUpdatedLabel; 43 | UILabel *_statusLabel; 44 | CALayer *_arrowImage; 45 | UIActivityIndicatorView *_activityView; 46 | 47 | 48 | } 49 | 50 | @property(nonatomic,assign) id delegate; 51 | 52 | - (void)refreshLastUpdatedDate; 53 | - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView; 54 | - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView; 55 | - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView; 56 | 57 | @end 58 | @protocol EGORefreshTableHeaderDelegate 59 | - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view; 60 | - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view; 61 | @optional 62 | - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view; 63 | @end 64 | -------------------------------------------------------------------------------- /IOSBoilerplate/EGORefreshTableHeaderView.m: -------------------------------------------------------------------------------- 1 | // 2 | // EGORefreshTableHeaderView.m 3 | // Demo 4 | // 5 | // Created by Devin Doty on 10/14/09October14. 6 | // Copyright 2009 enormego. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in 16 | // all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | // THE SOFTWARE. 25 | // 26 | 27 | #import "EGORefreshTableHeaderView.h" 28 | 29 | 30 | #define TEXT_COLOR [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0] 31 | #define FLIP_ANIMATION_DURATION 0.18f 32 | 33 | 34 | @interface EGORefreshTableHeaderView (Private) 35 | - (void)setState:(EGOPullRefreshState)aState; 36 | @end 37 | 38 | @implementation EGORefreshTableHeaderView 39 | 40 | @synthesize delegate=_delegate; 41 | 42 | 43 | - (id)initWithFrame:(CGRect)frame { 44 | if (self = [super initWithFrame:frame]) { 45 | 46 | self.autoresizingMask = UIViewAutoresizingFlexibleWidth; 47 | self.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0]; 48 | 49 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)]; 50 | label.autoresizingMask = UIViewAutoresizingFlexibleWidth; 51 | label.font = [UIFont systemFontOfSize:12.0f]; 52 | label.textColor = TEXT_COLOR; 53 | label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; 54 | label.shadowOffset = CGSizeMake(0.0f, 1.0f); 55 | label.backgroundColor = [UIColor clearColor]; 56 | label.textAlignment = UITextAlignmentCenter; 57 | [self addSubview:label]; 58 | _lastUpdatedLabel=label; 59 | [label release]; 60 | 61 | label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)]; 62 | label.autoresizingMask = UIViewAutoresizingFlexibleWidth; 63 | label.font = [UIFont boldSystemFontOfSize:13.0f]; 64 | label.textColor = TEXT_COLOR; 65 | label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f]; 66 | label.shadowOffset = CGSizeMake(0.0f, 1.0f); 67 | label.backgroundColor = [UIColor clearColor]; 68 | label.textAlignment = UITextAlignmentCenter; 69 | [self addSubview:label]; 70 | _statusLabel=label; 71 | [label release]; 72 | 73 | CALayer *layer = [CALayer layer]; 74 | layer.frame = CGRectMake(25.0f, frame.size.height - 65.0f, 30.0f, 55.0f); 75 | layer.contentsGravity = kCAGravityResizeAspect; 76 | layer.contents = (id)[UIImage imageNamed:@"blueArrow.png"].CGImage; 77 | 78 | #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000 79 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { 80 | layer.contentsScale = [[UIScreen mainScreen] scale]; 81 | } 82 | #endif 83 | 84 | [[self layer] addSublayer:layer]; 85 | _arrowImage=layer; 86 | 87 | UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; 88 | view.frame = CGRectMake(25.0f, frame.size.height - 38.0f, 20.0f, 20.0f); 89 | [self addSubview:view]; 90 | _activityView = view; 91 | [view release]; 92 | 93 | 94 | [self setState:EGOOPullRefreshNormal]; 95 | 96 | } 97 | 98 | return self; 99 | 100 | } 101 | 102 | 103 | #pragma mark - 104 | #pragma mark Setters 105 | 106 | - (void)refreshLastUpdatedDate { 107 | 108 | if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceLastUpdated:)]) { 109 | 110 | NSDate *date = [_delegate egoRefreshTableHeaderDataSourceLastUpdated:self]; 111 | 112 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 113 | [formatter setAMSymbol:@"AM"]; 114 | [formatter setPMSymbol:@"PM"]; 115 | [formatter setDateFormat:@"MM/dd/yyyy hh:mm:a"]; 116 | _lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [formatter stringFromDate:date]]; 117 | [[NSUserDefaults standardUserDefaults] setObject:_lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"]; 118 | [[NSUserDefaults standardUserDefaults] synchronize]; 119 | [formatter release]; 120 | 121 | } else { 122 | 123 | _lastUpdatedLabel.text = nil; 124 | 125 | } 126 | 127 | } 128 | 129 | - (void)setState:(EGOPullRefreshState)aState{ 130 | 131 | switch (aState) { 132 | case EGOOPullRefreshPulling: 133 | 134 | _statusLabel.text = NSLocalizedString(@"Release to refresh...", @"Release to refresh status"); 135 | [CATransaction begin]; 136 | [CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION]; 137 | _arrowImage.transform = CATransform3DMakeRotation((M_PI / 180.0) * 180.0f, 0.0f, 0.0f, 1.0f); 138 | [CATransaction commit]; 139 | 140 | break; 141 | case EGOOPullRefreshNormal: 142 | 143 | if (_state == EGOOPullRefreshPulling) { 144 | [CATransaction begin]; 145 | [CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION]; 146 | _arrowImage.transform = CATransform3DIdentity; 147 | [CATransaction commit]; 148 | } 149 | 150 | _statusLabel.text = NSLocalizedString(@"Pull down to refresh...", @"Pull down to refresh status"); 151 | [_activityView stopAnimating]; 152 | [CATransaction begin]; 153 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 154 | _arrowImage.hidden = NO; 155 | _arrowImage.transform = CATransform3DIdentity; 156 | [CATransaction commit]; 157 | 158 | [self refreshLastUpdatedDate]; 159 | 160 | break; 161 | case EGOOPullRefreshLoading: 162 | 163 | _statusLabel.text = NSLocalizedString(@"Loading...", @"Loading Status"); 164 | [_activityView startAnimating]; 165 | [CATransaction begin]; 166 | [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions]; 167 | _arrowImage.hidden = YES; 168 | [CATransaction commit]; 169 | 170 | break; 171 | default: 172 | break; 173 | } 174 | 175 | _state = aState; 176 | } 177 | 178 | 179 | #pragma mark - 180 | #pragma mark ScrollView Methods 181 | 182 | - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView { 183 | 184 | if (_state == EGOOPullRefreshLoading) { 185 | 186 | CGFloat offset = MAX(scrollView.contentOffset.y * -1, 0); 187 | offset = MIN(offset, 60); 188 | scrollView.contentInset = UIEdgeInsetsMake(offset, 0.0f, 0.0f, 0.0f); 189 | 190 | } else if (scrollView.isDragging) { 191 | 192 | BOOL _loading = NO; 193 | if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]) { 194 | _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self]; 195 | } 196 | 197 | if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_loading) { 198 | [self setState:EGOOPullRefreshNormal]; 199 | } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_loading) { 200 | [self setState:EGOOPullRefreshPulling]; 201 | } 202 | 203 | if (scrollView.contentInset.top != 0) { 204 | scrollView.contentInset = UIEdgeInsetsZero; 205 | } 206 | 207 | } 208 | 209 | } 210 | 211 | - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView { 212 | 213 | BOOL _loading = NO; 214 | if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]) { 215 | _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self]; 216 | } 217 | 218 | if (scrollView.contentOffset.y <= - 65.0f && !_loading) { 219 | 220 | if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) { 221 | [_delegate egoRefreshTableHeaderDidTriggerRefresh:self]; 222 | } 223 | 224 | [self setState:EGOOPullRefreshLoading]; 225 | [UIView beginAnimations:nil context:NULL]; 226 | [UIView setAnimationDuration:0.2]; 227 | scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f); 228 | [UIView commitAnimations]; 229 | 230 | } 231 | 232 | } 233 | 234 | - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView { 235 | 236 | [UIView beginAnimations:nil context:NULL]; 237 | [UIView setAnimationDuration:.3]; 238 | [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)]; 239 | [UIView commitAnimations]; 240 | 241 | [self setState:EGOOPullRefreshNormal]; 242 | 243 | } 244 | 245 | 246 | #pragma mark - 247 | #pragma mark Dealloc 248 | 249 | - (void)dealloc { 250 | 251 | _delegate=nil; 252 | _activityView = nil; 253 | _statusLabel = nil; 254 | _arrowImage = nil; 255 | _lastUpdatedLabel = nil; 256 | [super dealloc]; 257 | } 258 | 259 | 260 | @end 261 | -------------------------------------------------------------------------------- /IOSBoilerplate/FastCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // FastCell.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface FastCell : UITableViewCell { 32 | 33 | } 34 | 35 | @property (nonatomic, retain) UIView* backView; 36 | @property (nonatomic, retain) UIView* contentView; 37 | 38 | 39 | - (void) drawContentView:(CGRect)r; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /IOSBoilerplate/FastCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // FastCell.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "FastCell.h" 30 | 31 | @interface ContentView : UIView 32 | @end 33 | 34 | @implementation ContentView 35 | 36 | - (void)drawRect:(CGRect)r 37 | { 38 | [(FastCell*)[self superview] drawContentView:r]; 39 | } 40 | 41 | @end 42 | 43 | @implementation FastCell 44 | 45 | @synthesize backView; 46 | @synthesize contentView; 47 | 48 | - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 49 | if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { 50 | backView = [[UIView alloc] initWithFrame:CGRectZero]; 51 | backView.opaque = YES; 52 | [self addSubview:backView]; 53 | 54 | contentView = [[ContentView alloc] initWithFrame:CGRectZero]; 55 | contentView.opaque = YES; 56 | [self addSubview:contentView]; 57 | } 58 | return self; 59 | } 60 | 61 | - (void)dealloc { 62 | [backView removeFromSuperview]; 63 | [backView release]; 64 | 65 | [contentView removeFromSuperview]; 66 | [contentView release]; 67 | [super dealloc]; 68 | } 69 | 70 | - (void)setFrame:(CGRect)f { 71 | [super setFrame:f]; 72 | CGRect b = [self bounds]; 73 | b.size.height -= 1; // leave room for the seperator line 74 | 75 | [backView setFrame:b]; 76 | [contentView setFrame:b]; 77 | [self setNeedsDisplay]; 78 | } 79 | 80 | - (void)setNeedsDisplay { 81 | [super setNeedsDisplay]; 82 | [backView setNeedsDisplay]; 83 | [contentView setNeedsDisplay]; 84 | } 85 | 86 | - (void)drawContentView:(CGRect)r { 87 | // subclasses should implement this 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /IOSBoilerplate/HTTPHUDExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPHUDExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface HTTPHUDExample : UIViewController { 32 | NSOperationQueue *_requestOperationQueue; 33 | } 34 | 35 | @property (nonatomic, retain) IBOutlet UILabel* label; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /IOSBoilerplate/HTTPHUDExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // HTTPHUDExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "HTTPHUDExample.h" 30 | #import "SVProgressHUD.h" 31 | #import "JSONKit.h" 32 | #import "DictionaryHelper.h" 33 | #import "AFJSONRequestOperation.h" 34 | 35 | @interface HTTPHUDExample () 36 | @property (readwrite, nonatomic, retain) NSOperationQueue *requestOperationQueue; 37 | @end 38 | 39 | @implementation HTTPHUDExample 40 | 41 | @synthesize label; 42 | @synthesize requestOperationQueue = _requestOperationQueue; 43 | 44 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 45 | { 46 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 47 | if (self) { 48 | self.requestOperationQueue = [[[NSOperationQueue alloc] init] autorelease]; 49 | } 50 | return self; 51 | } 52 | 53 | - (void)didReceiveMemoryWarning 54 | { 55 | // Releases the view if it doesn't have a superview. 56 | [super didReceiveMemoryWarning]; 57 | 58 | // Release any cached data, images, etc that aren't in use. 59 | } 60 | 61 | #pragma mark - View lifecycle 62 | 63 | - (void)viewDidLoad 64 | { 65 | [super viewDidLoad]; 66 | self.title = @"HTTP + HUD + JSON parsing"; 67 | label.text = @"Loading..."; 68 | } 69 | 70 | - (void)viewDidUnload 71 | { 72 | [super viewDidUnload]; 73 | // Release any retained subviews of the main view. 74 | // e.g. self.myOutlet = nil; 75 | } 76 | 77 | - (void)viewDidAppear:(BOOL)animated { 78 | [super viewDidAppear:animated]; 79 | } 80 | 81 | - (void)viewWillAppear:(BOOL)animated { 82 | [super viewWillAppear:animated]; 83 | 84 | [SVProgressHUD showInView:self.view]; 85 | 86 | NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.twitter.com/1/statuses/show.json?id=125372508387024896&include_entities=false"]]; 87 | AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 88 | label.text = [JSON valueForKeyPath:@"text"]; 89 | [SVProgressHUD dismissWithSuccess:@"Ok!"]; 90 | } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 91 | label.text = @"error"; 92 | [SVProgressHUD dismissWithError:[error localizedDescription]]; 93 | }]; 94 | [operation start]; 95 | } 96 | 97 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 98 | return YES; 99 | } 100 | 101 | - (void)dealloc { 102 | [label release]; 103 | 104 | [super dealloc]; 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /IOSBoilerplate/IOSBoilerplate-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | net.gimenete.iosboilerplate 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 1.0 27 | LSRequiresIPhoneOS 28 | 29 | NSMainNibFile 30 | MainWindow 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /IOSBoilerplate/IOSBoilerplate-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'IOSBoilerplate' target in the 'IOSBoilerplate' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /IOSBoilerplate/IOSBoilerplateAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSBoilerplateAppDelegate.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface IOSBoilerplateAppDelegate : NSObject 32 | 33 | @property (nonatomic, retain) IBOutlet UIWindow *window; 34 | 35 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 36 | 37 | + (IOSBoilerplateAppDelegate*) sharedAppDelegate; 38 | 39 | - (BOOL)openURL:(NSURL*)url; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /IOSBoilerplate/IOSBoilerplateAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // IOSBoilerplateAppDelegate.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "IOSBoilerplateAppDelegate.h" 30 | #import "AFURLCache.h" 31 | #import "BrowserViewController.h" 32 | 33 | @implementation IOSBoilerplateAppDelegate 34 | 35 | @synthesize window = _window; 36 | @synthesize navigationController = _navigationController; 37 | 38 | + (IOSBoilerplateAppDelegate*) sharedAppDelegate { 39 | return (IOSBoilerplateAppDelegate*) [UIApplication sharedApplication].delegate; 40 | } 41 | 42 | - (BOOL)openURL:(NSURL*)url 43 | { 44 | BrowserViewController *bvc = [[BrowserViewController alloc] initWithUrls:url]; 45 | [self.navigationController pushViewController:bvc animated:YES]; 46 | [bvc release]; 47 | 48 | return YES; 49 | } 50 | 51 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 52 | { 53 | // use custom URLCache to get disk caching on iOS 54 | AFURLCache *URLCache = [[[AFURLCache alloc] initWithMemoryCapacity:1024*1024 // 1MB mem cache 55 | diskCapacity:1024*1024*5 // 5MB disk cache 56 | diskPath:[AFURLCache defaultCachePath]] autorelease]; 57 | 58 | [NSURLCache setSharedURLCache:URLCache]; 59 | 60 | self.window.rootViewController = self.navigationController; 61 | [self.window makeKeyAndVisible]; 62 | return YES; 63 | } 64 | 65 | - (void)applicationWillResignActive:(UIApplication *)application 66 | { 67 | /* 68 | 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. 69 | 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. 70 | */ 71 | } 72 | 73 | - (void)applicationDidEnterBackground:(UIApplication *)application 74 | { 75 | /* 76 | 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. 77 | If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 78 | */ 79 | } 80 | 81 | - (void)applicationWillEnterForeground:(UIApplication *)application 82 | { 83 | /* 84 | 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. 85 | */ 86 | } 87 | 88 | - (void)applicationDidBecomeActive:(UIApplication *)application 89 | { 90 | /* 91 | 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. 92 | */ 93 | } 94 | 95 | - (void)applicationWillTerminate:(UIApplication *)application 96 | { 97 | /* 98 | Called when the application is about to terminate. 99 | Save data if appropriate. 100 | See also applicationDidEnterBackground:. 101 | */ 102 | } 103 | 104 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 105 | 106 | } 107 | 108 | - (void)dealloc 109 | { 110 | [_window release]; 111 | [_navigationController release]; 112 | [super dealloc]; 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /IOSBoilerplate/ListViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ListViewController.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "EGORefreshTableHeaderView.h" 30 | 31 | @interface ListViewController : UIViewController { 32 | 33 | EGORefreshTableHeaderView *_refreshHeaderView; 34 | BOOL _reloading; 35 | 36 | } 37 | 38 | @property (nonatomic, retain) IBOutlet UITableView* table; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /IOSBoilerplate/ListViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ListViewController.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "ListViewController.h" 30 | 31 | @implementation ListViewController 32 | 33 | @synthesize table; 34 | 35 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 36 | { 37 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 38 | if (self) { 39 | // Custom initialization 40 | } 41 | return self; 42 | } 43 | 44 | - (void)didReceiveMemoryWarning 45 | { 46 | // Releases the view if it doesn't have a superview. 47 | [super didReceiveMemoryWarning]; 48 | 49 | // Release any cached data, images, etc that aren't in use. 50 | } 51 | 52 | - (void)viewDidLoad { 53 | [super viewDidLoad]; 54 | 55 | if (_refreshHeaderView == nil) { 56 | 57 | EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.table.bounds.size.height, self.view.frame.size.width, self.table.bounds.size.height)]; 58 | view.delegate = self; 59 | [self.table addSubview:view]; 60 | _refreshHeaderView = view; 61 | [view release]; 62 | 63 | } 64 | 65 | // update the last update date 66 | [_refreshHeaderView refreshLastUpdatedDate]; 67 | } 68 | 69 | #pragma mark - 70 | #pragma mark Data Source Loading / Reloading Methods 71 | 72 | - (void)reloadTableViewDataSource { 73 | _reloading = YES; 74 | // TO be implemented 75 | } 76 | 77 | - (void)doneLoadingTableViewData { 78 | // model should call this when its done loading 79 | _reloading = NO; 80 | [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.table]; 81 | } 82 | 83 | 84 | #pragma mark - 85 | #pragma mark UIScrollViewDelegate Methods 86 | 87 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 88 | [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; 89 | } 90 | 91 | - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 92 | [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; 93 | } 94 | 95 | 96 | #pragma mark - 97 | #pragma mark EGORefreshTableHeaderDelegate Methods 98 | 99 | - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{ 100 | [self reloadTableViewDataSource]; 101 | } 102 | 103 | - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view { 104 | return _reloading; // should return if data source model is reloading 105 | } 106 | 107 | - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view { 108 | return [NSDate date]; // should return date data source was last changed 109 | } 110 | 111 | 112 | #pragma mark - View lifecycle 113 | 114 | /* 115 | // Implement loadView to create a view hierarchy programmatically, without using a nib. 116 | - (void)loadView 117 | { 118 | } 119 | */ 120 | 121 | /* 122 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 123 | - (void)viewDidLoad 124 | { 125 | [super viewDidLoad]; 126 | } 127 | */ 128 | 129 | - (void)viewDidUnload 130 | { 131 | [super viewDidUnload]; 132 | _refreshHeaderView = nil; 133 | } 134 | 135 | - (void)dealloc { 136 | [table release]; 137 | _refreshHeaderView = nil; 138 | [super dealloc]; 139 | } 140 | 141 | @end 142 | -------------------------------------------------------------------------------- /IOSBoilerplate/MyApplication.h: -------------------------------------------------------------------------------- 1 | // 2 | // MyApplication.h 3 | // 4 | // This software is licensed under the MIT Software License 5 | // 6 | // Copyright (c) 2011 Nathan Buggia 7 | // http://nathanbuggia.com/posts/browser-view-controller/ 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 10 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation 11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 12 | // to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 15 | // the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 18 | // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // Artwork generously contributed by Joseph Wain of http://glyphish.com (buy his Pro pack of icons!) 24 | // 25 | 26 | 27 | #import 28 | #import "IOSBoilerplateAppDelegate.h" 29 | 30 | 31 | @interface MyApplication : UIApplication 32 | 33 | -(BOOL)openURL:(NSURL *)url; 34 | 35 | -(BOOL)openURL:(NSURL *)url forceOpenInSafari:(BOOL)forceOpenInSafari; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /IOSBoilerplate/MyApplication.m: -------------------------------------------------------------------------------- 1 | // 2 | // MyApplication.m 3 | // 4 | // This software is licensed under the MIT Software License 5 | // 6 | // Copyright (c) 2011 Nathan Buggia 7 | // http://nathanbuggia.com/posts/browser-view-controller/ 8 | // 9 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 10 | // documentation files (the "Software"), to deal in the Software without restriction, including without limitation 11 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 12 | // to permit persons to whom the Software is furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of 15 | // the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 18 | // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // Artwork generously contributed by Joseph Wain of http://glyphish.com (buy his Pro pack of icons!) 24 | // 25 | 26 | 27 | #import "MyApplication.h" 28 | 29 | @implementation MyApplication 30 | 31 | 32 | - (BOOL)openURL:(NSURL *)url 33 | { 34 | return [self openURL:url forceOpenInSafari:NO]; 35 | } 36 | 37 | 38 | -(BOOL)openURL:(NSURL *)url forceOpenInSafari:(BOOL)forceOpenInSafari 39 | { 40 | if(forceOpenInSafari) 41 | { 42 | // We're overriding our app trying to open this URL, so we'll let UIApplication federate this request back out 43 | // through the normal channels. The return value states whether or not they were able to open the URL. 44 | return [super openURL:url]; 45 | } 46 | 47 | // 48 | // Otherwise, we'll see if it is a request that we should let our app open. 49 | 50 | BOOL couldWeOpenUrl = NO; 51 | 52 | NSString* scheme = [url.scheme lowercaseString]; 53 | if([scheme compare:@"http"] == NSOrderedSame 54 | || [scheme compare:@"https"] == NSOrderedSame) 55 | { 56 | // TODO - Here you might also want to check for other conditions where you do not want your app opening URLs (e.g. 57 | // Facebook authentication requests, OAUTH requests, etc) 58 | 59 | // TODO - Update the cast below with the name of your AppDelegate 60 | // Let's call the method you wrote on your AppDelegate to actually open the BrowserViewController 61 | // NATE 62 | couldWeOpenUrl = [(IOSBoilerplateAppDelegate*)self.delegate openURL:url]; 63 | } 64 | 65 | if(!couldWeOpenUrl) 66 | { 67 | return [super openURL:url]; 68 | } 69 | else 70 | { 71 | return YES; 72 | } 73 | } 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /IOSBoilerplate/PullDownExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // PullDownExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "ListViewController.h" 30 | 31 | @interface PullDownExample : ListViewController 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /IOSBoilerplate/PullDownExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // PullDownExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "PullDownExample.h" 30 | 31 | @implementation PullDownExample 32 | 33 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 34 | { 35 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 36 | if (self) { 37 | // Custom initialization 38 | } 39 | return self; 40 | } 41 | 42 | - (void)didReceiveMemoryWarning 43 | { 44 | [super didReceiveMemoryWarning]; 45 | } 46 | 47 | #pragma mark - ListViewController 48 | 49 | // This is the core method you should implement 50 | - (void)reloadTableViewDataSource { 51 | _reloading = YES; 52 | 53 | // Here you would make an HTTP request or something like that 54 | // Call [self doneLoadingTableViewData] when you are done 55 | [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0]; 56 | } 57 | 58 | #pragma mark - 59 | #pragma mark UITableViewDataSource 60 | 61 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 62 | return 1; 63 | } 64 | 65 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 66 | return 50; 67 | } 68 | 69 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 70 | 71 | static NSString *CellIdentifier = @"Cell"; 72 | 73 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 74 | if (cell == nil) { 75 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 76 | } 77 | 78 | cell.textLabel.text = [NSString stringWithFormat:@"Cell #%d", indexPath.row]; 79 | 80 | return cell; 81 | } 82 | 83 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 84 | return [NSString stringWithFormat:@"Section %i", section]; 85 | } 86 | 87 | #pragma mark - 88 | #pragma mark UITableViewDelegate 89 | 90 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 91 | NSLog(@"selected cell at section #%d and row #%d", indexPath.section, indexPath.row); 92 | } 93 | 94 | #pragma mark - View lifecycle 95 | 96 | - (void)viewDidLoad 97 | { 98 | [super viewDidLoad]; 99 | self.title = @"Pull down example"; 100 | } 101 | 102 | - (void)viewDidUnload 103 | { 104 | [super viewDidUnload]; // Always call superclass methods first, since you are using inheritance 105 | } 106 | 107 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 108 | { 109 | return YES; 110 | } 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /IOSBoilerplate/RootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface RootViewController : UIViewController { 32 | 33 | } 34 | 35 | @property (nonatomic, retain) IBOutlet UITableView* table; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /IOSBoilerplate/RootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "RootViewController.h" 30 | #import "HTTPHUDExample.h" 31 | #import "AsyncImageExample.h" 32 | #import "AsyncCellImagesExample.h" 33 | #import "VariableHeightExample.h" 34 | #import "DirectionsExample.h" 35 | #import "AutocompleteLocationExample.h" 36 | #import "PullDownExample.h" 37 | #import "SwipeableTableViewExample.h" 38 | #import "BrowserSampleViewController.h" 39 | 40 | @implementation RootViewController 41 | 42 | @synthesize table; 43 | 44 | - (void)viewDidLoad 45 | { 46 | [super viewDidLoad]; 47 | self.title = @"Demos"; 48 | } 49 | 50 | - (void)viewWillAppear:(BOOL)animated 51 | { 52 | [super viewWillAppear:animated]; 53 | } 54 | 55 | - (void)viewDidAppear:(BOOL)animated 56 | { 57 | [super viewDidAppear:animated]; 58 | } 59 | 60 | - (void)viewWillDisappear:(BOOL)animated 61 | { 62 | [super viewWillDisappear:animated]; 63 | } 64 | 65 | - (void)viewDidDisappear:(BOOL)animated 66 | { 67 | [super viewDidDisappear:animated]; 68 | } 69 | 70 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 71 | return YES; 72 | } 73 | 74 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 75 | { 76 | return 4; 77 | } 78 | 79 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 80 | switch (section) { 81 | case 0: 82 | return @"HTTP requests"; 83 | break; 84 | 85 | case 1: 86 | return @"UITableView"; 87 | break; 88 | 89 | case 2: 90 | return @"Maps & locations"; 91 | break; 92 | 93 | case 3: 94 | return @"Web Browser"; 95 | break; 96 | 97 | default: 98 | break; 99 | } 100 | return nil; 101 | } 102 | 103 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 104 | { 105 | switch (section) { 106 | case 0: 107 | return 3; 108 | break; 109 | 110 | case 1: 111 | return 3; 112 | break; 113 | 114 | case 2: 115 | return 2; 116 | break; 117 | 118 | case 3: 119 | return 1; 120 | break; 121 | 122 | default: 123 | break; 124 | } 125 | return 0; 126 | } 127 | 128 | // Customize the appearance of table view cells. 129 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 130 | { 131 | static NSString *CellIdentifier = @"Cell"; 132 | 133 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 134 | if (cell == nil) { 135 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 136 | } 137 | 138 | if (indexPath.section == 0) { 139 | switch (indexPath.row) { 140 | case 0: 141 | cell.textLabel.text = @"HUD + JSON parsing"; 142 | cell.detailTextLabel.text = @"Shows a HUD spinner and parses JSON"; 143 | break; 144 | 145 | case 1: 146 | cell.textLabel.text = @"Async image"; 147 | cell.detailTextLabel.text = @"Loads a simple image asynchronously"; 148 | break; 149 | 150 | case 2: 151 | cell.textLabel.text = @"Async cell images"; 152 | cell.detailTextLabel.text = @"Loads images inside cells asynchronously"; 153 | break; 154 | 155 | default: 156 | break; 157 | } 158 | } else if (indexPath.section == 1) { 159 | switch (indexPath.row) { 160 | case 0: 161 | cell.textLabel.text = @"Variable-height cells"; 162 | cell.detailTextLabel.text = @"Implements a FastCell with variable height"; 163 | break; 164 | 165 | case 1: 166 | cell.textLabel.text = @"Pull down to refresh"; 167 | cell.detailTextLabel.text = @"Extends a base class to add that feature"; 168 | break; 169 | 170 | case 2: 171 | cell.textLabel.text = @"Swipe cell"; 172 | cell.detailTextLabel.text = @"Demonstrates how to make swipeable cells"; 173 | break; 174 | 175 | default: 176 | break; 177 | } 178 | } else if (indexPath.section == 2) { 179 | switch (indexPath.row) { 180 | case 0: 181 | cell.textLabel.text = @"Directions"; 182 | cell.detailTextLabel.text = @"Map Overlays + Google Maps API"; 183 | break; 184 | 185 | case 1: 186 | cell.textLabel.text = @"Autocomplete location"; 187 | cell.detailTextLabel.text = @"Uses the Google Maps API to search locations"; 188 | break; 189 | 190 | default: 191 | break; 192 | } 193 | } else if (indexPath.section == 3) { 194 | switch (indexPath.row) { 195 | case 0: 196 | cell.textLabel.text = @"Web Browser integration"; 197 | cell.detailTextLabel.text = @"Open URLs from UITextViews, UIWebViews, UITableViews, and UIButtons"; 198 | break; 199 | 200 | default: 201 | break; 202 | } 203 | } 204 | 205 | return cell; 206 | } 207 | 208 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 209 | { 210 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 211 | 212 | UIViewController* vc = nil; 213 | 214 | if (indexPath.section == 0) { 215 | switch (indexPath.row) { 216 | case 0: 217 | vc = [[HTTPHUDExample alloc] init]; 218 | break; 219 | 220 | case 1: 221 | vc = [[AsyncImageExample alloc] init]; 222 | break; 223 | 224 | case 2: 225 | vc = [[AsyncCellImagesExample alloc] init]; 226 | break; 227 | 228 | default: 229 | break; 230 | } 231 | } else if (indexPath.section == 1) { 232 | switch (indexPath.row) { 233 | case 0: 234 | vc = [[VariableHeightExample alloc] init]; 235 | break; 236 | 237 | case 1: 238 | vc = [[PullDownExample alloc] init]; 239 | break; 240 | 241 | case 2: 242 | vc = [[SwipeableTableViewExample alloc] init]; 243 | break; 244 | 245 | default: 246 | break; 247 | } 248 | } else if (indexPath.section == 2) { 249 | switch (indexPath.row) { 250 | case 0: 251 | vc = [[DirectionsExample alloc] init]; 252 | break; 253 | 254 | case 1: 255 | vc = [[AutocompleteLocationExample alloc] init]; 256 | break; 257 | 258 | default: 259 | break; 260 | } 261 | } else if (indexPath.section == 3) { 262 | switch (indexPath.row) { 263 | case 0: 264 | vc = [[BrowserSampleViewController alloc] init]; 265 | break; 266 | 267 | default: 268 | break; 269 | } 270 | } 271 | 272 | if (vc) { 273 | [self.navigationController pushViewController:vc animated:YES]; 274 | [vc release]; 275 | } 276 | 277 | } 278 | 279 | - (void)didReceiveMemoryWarning 280 | { 281 | [super didReceiveMemoryWarning]; 282 | } 283 | 284 | - (void)viewDidUnload 285 | { 286 | [super viewDidUnload]; 287 | } 288 | 289 | - (void)dealloc 290 | { 291 | [table release]; 292 | 293 | [super dealloc]; 294 | } 295 | 296 | @end 297 | -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/SVProgressHUD/.DS_Store -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/error.png -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/error@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/error@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/success.png -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/success@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/SVProgressHUD/SVProgressHUD.bundle/success@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/SVProgressHUD/SVProgressHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVProgressHUD.h 3 | // 4 | // Created by Sam Vermette on 27.03.11. 5 | // Copyright 2011 Sam Vermette. All rights reserved. 6 | // 7 | 8 | typedef enum { 9 | SVProgressHUDMaskTypeNone, // allow user interactions while HUD is displayed 10 | SVProgressHUDMaskTypeClear, // don't allow 11 | SVProgressHUDMaskTypeBlack // don't allow and dim the UI in the back of the HUD 12 | } SVProgressHUDMaskType; 13 | 14 | @interface SVProgressHUD : UIView { 15 | UIView *_maskView; 16 | } 17 | 18 | /* 19 | showInView:(UIView*) -> the view you're adding the HUD to. By default, it's added to the keyWindow rootViewController, or the keyWindow if the rootViewController is nil 20 | status:(NSString*) -> a loading status for the HUD (different from the success and error messages) 21 | networkIndicator:(BOOL) -> whether or not the HUD also triggers the UIApplication's network activity indicator (default is YES) 22 | posY:(CGFloat) -> the vertical position of the HUD (default is viewHeight/2-viewHeight/8) 23 | maskType:(SVProgressHUDMaskType) -> set whether to allow user interactions while HUD is displayed 24 | */ 25 | 26 | + (void)show; 27 | + (void)showInView:(UIView*)view; 28 | + (void)showInView:(UIView*)view status:(NSString*)string; 29 | + (void)showInView:(UIView*)view status:(NSString*)string networkIndicator:(BOOL)show; 30 | + (void)showInView:(UIView*)view status:(NSString*)string networkIndicator:(BOOL)show posY:(CGFloat)posY; 31 | + (void)showInView:(UIView*)view status:(NSString*)string networkIndicator:(BOOL)show posY:(CGFloat)posY maskType:(SVProgressHUDMaskType)maskType; 32 | 33 | + (void)setStatus:(NSString*)string; // change the HUD loading status while it's showing 34 | 35 | + (void)dismiss; // simply dismiss the HUD with a fade+scale out animation 36 | + (void)dismissWithSuccess:(NSString*)successString; // also displays the success icon image 37 | + (void)dismissWithSuccess:(NSString*)successString afterDelay:(NSTimeInterval)seconds; 38 | + (void)dismissWithError:(NSString*)errorString; // also displays the error icon image 39 | + (void)dismissWithError:(NSString*)errorString afterDelay:(NSTimeInterval)seconds; 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /IOSBoilerplate/StringHelper.h: -------------------------------------------------------------------------------- 1 | // 2 | // StringHelper.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface NSString (helper) 32 | 33 | - (NSString*)substringFrom:(NSInteger)a to:(NSInteger)b; 34 | 35 | - (NSInteger)indexOf:(NSString*)substring from:(NSInteger)starts; 36 | 37 | - (NSString*)trim; 38 | 39 | - (BOOL)startsWith:(NSString*)s; 40 | 41 | - (BOOL)containsString:(NSString*)aString; 42 | 43 | - (NSString*)urlEncode; 44 | 45 | - (NSString*)sha1; 46 | 47 | @end 48 | 49 | -------------------------------------------------------------------------------- /IOSBoilerplate/StringHelper.m: -------------------------------------------------------------------------------- 1 | // 2 | // StringHelper.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "StringHelper.h" 30 | #import "DataHelper.h" 31 | #import 32 | 33 | @implementation NSString (helper) 34 | 35 | - (NSString*)substringFrom:(NSInteger)a to:(NSInteger)b { 36 | NSRange r; 37 | r.location = a; 38 | r.length = b - a; 39 | return [self substringWithRange:r]; 40 | } 41 | 42 | - (NSInteger)indexOf:(NSString*)substring from:(NSInteger)starts { 43 | NSRange r; 44 | r.location = starts; 45 | r.length = [self length] - r.location; 46 | 47 | NSRange index = [self rangeOfString:substring options:NSLiteralSearch range:r]; 48 | if (index.location == NSNotFound) { 49 | return -1; 50 | } 51 | return index.location + index.length; 52 | } 53 | 54 | - (NSString*)trim { 55 | return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 56 | } 57 | 58 | - (BOOL)startsWith:(NSString*)s { 59 | if([self length] < [s length]) return NO; 60 | return [s isEqualToString:[self substringFrom:0 to:[s length]]]; 61 | } 62 | 63 | - (BOOL)containsString:(NSString *)aString 64 | { 65 | NSRange range = [[self lowercaseString] rangeOfString:[aString lowercaseString]]; 66 | return range.location != NSNotFound; 67 | } 68 | 69 | - (NSString *)urlEncode 70 | { 71 | NSString* encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes( 72 | NULL, 73 | (CFStringRef) self, 74 | NULL, 75 | (CFStringRef)@"!*'();:@&=+$,/?%#[]", 76 | kCFStringEncodingUTF8 ); 77 | return [encodedString autorelease]; 78 | } 79 | 80 | - (NSString *)sha1 { 81 | NSData *data = [self dataUsingEncoding:NSUTF8StringEncoding]; 82 | uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0}; 83 | CC_SHA1(data.bytes, data.length, digest); 84 | NSData *d = [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH]; 85 | return [d hexString]; 86 | } 87 | 88 | @end 89 | -------------------------------------------------------------------------------- /IOSBoilerplate/SwipeableCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableCell.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "FastCell.h" 30 | 31 | @interface SwipeableCell : FastCell { 32 | 33 | BOOL swipe; 34 | 35 | } 36 | 37 | @property (nonatomic, retain) NSDictionary* info; 38 | 39 | - (void) updateCellInfo:(NSDictionary*)_info; 40 | 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /IOSBoilerplate/SwipeableCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableCell.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "SwipeableCell.h" 30 | #import "DictionaryHelper.h" 31 | 32 | @implementation SwipeableCell 33 | 34 | @synthesize info; 35 | 36 | - (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 37 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 38 | { 39 | self.backgroundColor = [UIColor whiteColor]; 40 | self.opaque = YES; 41 | 42 | // configure "backView" 43 | UIButton* b = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 44 | b.frame = CGRectMake(5, 5, 100, 30); 45 | [b setTitle:@"Hi there!" forState:UIControlStateNormal]; 46 | [b setTitle:@"Hi there!" forState:UIControlStateHighlighted]; 47 | [b setTitle:@"Hi there!" forState:UIControlStateSelected]; 48 | [self.backView addSubview:b]; 49 | self.backView.backgroundColor = [UIColor groupTableViewBackgroundColor]; 50 | 51 | [b addTarget:self action:@selector(doSomething) forControlEvents:UIControlEventTouchUpInside]; 52 | } 53 | return self; 54 | } 55 | 56 | - (void) doSomething { 57 | NSLog(@"do something"); 58 | 59 | UIView* view = self.superview; 60 | if ([view isKindOfClass:[UITableView class]]) { 61 | UITableView* table = (UITableView*)view; 62 | [table setEditing:NO animated:YES]; 63 | } 64 | } 65 | 66 | - (void) prepareForReuse { 67 | [super prepareForReuse]; 68 | } 69 | 70 | static UIFont* bold22 = nil; 71 | 72 | + (void)initialize 73 | { 74 | if(self == [SwipeableCell class]) 75 | { 76 | bold22 = [[UIFont boldSystemFontOfSize:22] retain]; 77 | } 78 | } 79 | 80 | - (void)dealloc { 81 | [info release]; 82 | 83 | [super dealloc]; 84 | } 85 | 86 | - (void) drawContentView:(CGRect)rect { 87 | CGContextRef context = UIGraphicsGetCurrentContext(); 88 | 89 | [[UIColor whiteColor] set]; 90 | CGContextFillRect(context, rect); 91 | 92 | NSString* text = [info stringForKey:@"text"]; 93 | 94 | [[UIColor blackColor] set]; 95 | [text drawAtPoint:CGPointMake(15.0, 10.0) forWidth:rect.size.width withFont:bold22 lineBreakMode:UILineBreakModeTailTruncation]; 96 | } 97 | 98 | - (void) updateCellInfo:(NSDictionary*)_info { 99 | self.info = _info; 100 | [self setNeedsDisplay]; 101 | } 102 | 103 | - (void) setEditing:(BOOL)editing animated:(BOOL)animated { 104 | // Do not call the super method. It shows a delete button by deafult 105 | // [super setEditing:editing animated:animated]; 106 | 107 | if (editing) { 108 | // swiped 109 | swipe = YES; 110 | [UIView beginAnimations:@"" context:nil]; 111 | [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 112 | CGRect frame = self.contentView.frame; 113 | // this makes visible just 10 points of the contentView 114 | frame.origin.x = self.contentView.frame.size.width - 10; 115 | self.contentView.frame = frame; 116 | [UIView commitAnimations]; 117 | } else if (swipe) { 118 | // swipe finished 119 | swipe = NO; 120 | 121 | [UIView beginAnimations:@"" context:nil]; 122 | [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 123 | CGRect frame = self.contentView.frame; 124 | frame.origin.x = 0; 125 | self.contentView.frame = frame; 126 | [UIView commitAnimations]; 127 | } 128 | 129 | // [self setNeedsDisplay]; 130 | } 131 | 132 | @end 133 | -------------------------------------------------------------------------------- /IOSBoilerplate/SwipeableTableViewExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableTableViewExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface SwipeableTableViewExample : UIViewController 32 | 33 | @property (nonatomic, retain) IBOutlet UITableView* table; 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /IOSBoilerplate/SwipeableTableViewExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // SwipeableTableViewExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "SwipeableTableViewExample.h" 30 | #import "SwipeableCell.h" 31 | 32 | @implementation SwipeableTableViewExample 33 | 34 | @synthesize table; 35 | 36 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 37 | { 38 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 39 | if (self) { 40 | // Custom initialization 41 | } 42 | return self; 43 | } 44 | 45 | - (void)didReceiveMemoryWarning 46 | { 47 | // Releases the view if it doesn't have a superview. 48 | [super didReceiveMemoryWarning]; 49 | 50 | // Release any cached data, images, etc that aren't in use. 51 | } 52 | 53 | - (void)scrollViewDidScroll:(UIScrollView *)scrollView { 54 | [table setEditing:NO animated:NO]; // cancel any swiped cell 55 | } 56 | 57 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 58 | } // just leave this method empty 59 | 60 | #pragma mark - 61 | #pragma mark UITableViewDataSource 62 | 63 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 64 | return 1; 65 | } 66 | 67 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 68 | return 50; 69 | } 70 | 71 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 72 | 73 | static NSString *CellIdentifier = @"Cell"; 74 | 75 | SwipeableCell *cell = (SwipeableCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 76 | if (cell == nil) { 77 | cell = [[[SwipeableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 78 | } 79 | 80 | NSString* text = [NSString stringWithFormat:@"Cell #%d", indexPath.row]; 81 | NSDictionary* info = [[NSDictionary alloc] initWithObjectsAndKeys:text, @"text", nil]; 82 | [cell updateCellInfo:info]; 83 | [info release]; 84 | 85 | return cell; 86 | } 87 | 88 | - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 89 | return [NSString stringWithFormat:@"Section %i", section]; 90 | } 91 | 92 | #pragma mark - 93 | #pragma mark UITableViewDelegate 94 | 95 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 96 | NSLog(@"selected cell at section #%d and row #%d", indexPath.section, indexPath.row); 97 | } 98 | 99 | #pragma mark - View lifecycle 100 | 101 | - (void)viewDidLoad 102 | { 103 | [super viewDidLoad]; 104 | self.title = @"Swipeable table example"; 105 | } 106 | 107 | - (void)viewDidUnload 108 | { 109 | [super viewDidUnload]; 110 | // Release any retained subviews of the main view. 111 | // e.g. self.myOutlet = nil; 112 | } 113 | 114 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 115 | { 116 | return YES; 117 | } 118 | 119 | - (void)dealloc { 120 | [table release]; 121 | [super dealloc]; 122 | } 123 | 124 | @end 125 | -------------------------------------------------------------------------------- /IOSBoilerplate/TwitterSearchClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterSearchClient.h 3 | // IOSBoilerplate 4 | // 5 | // Created by Mattt Thompson on 11/10/31. 6 | // Copyright (c) 2011年 Gowalla. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AFHTTPClient.h" 11 | 12 | @interface TwitterSearchClient : AFHTTPClient 13 | + (TwitterSearchClient *)sharedClient; 14 | @end 15 | -------------------------------------------------------------------------------- /IOSBoilerplate/TwitterSearchClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterSearchClient.m 3 | // IOSBoilerplate 4 | // 5 | // Created by Mattt Thompson on 11/10/31. 6 | // Copyright (c) 2011年 Gowalla. All rights reserved. 7 | // 8 | 9 | #import "TwitterSearchClient.h" 10 | 11 | #import "AFJSONRequestOperation.h" 12 | 13 | NSString * const kTwitterBaseURLString = @"https://search.twitter.com/"; 14 | 15 | 16 | @implementation TwitterSearchClient 17 | 18 | + (TwitterSearchClient *)sharedClient { 19 | static TwitterSearchClient *_sharedClient = nil; 20 | static dispatch_once_t oncePredicate; 21 | dispatch_once(&oncePredicate, ^{ 22 | _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kTwitterBaseURLString]]; 23 | }); 24 | 25 | return _sharedClient; 26 | } 27 | 28 | - (id)initWithBaseURL:(NSURL *)url { 29 | self = [super initWithBaseURL:url]; 30 | if (!self) { 31 | return nil; 32 | } 33 | 34 | [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; 35 | 36 | // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 37 | [self setDefaultHeader:@"Accept" value:@"application/json"]; 38 | 39 | // X-UDID HTTP Header 40 | [self setDefaultHeader:@"X-UDID" value:[[UIDevice currentDevice] uniqueIdentifier]]; 41 | 42 | return self; 43 | } 44 | 45 | 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /IOSBoilerplate/VariableHeightCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // VariableHeightCell.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "FastCell.h" 30 | 31 | @interface VariableHeightCell : FastCell 32 | 33 | @property (nonatomic, retain) NSDictionary* info; 34 | 35 | - (void) updateCellInfo:(NSDictionary*)_info; 36 | + (CGFloat) heightForCellWithInfo:(NSDictionary*)_info inTable:(UITableView *)tableView; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /IOSBoilerplate/VariableHeightCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // VariableHeightCell.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "VariableHeightCell.h" 30 | #import "DictionaryHelper.h" 31 | 32 | @implementation VariableHeightCell 33 | 34 | @synthesize info; 35 | 36 | - (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 37 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) 38 | { 39 | self.backgroundColor = [UIColor whiteColor]; 40 | self.opaque = YES; 41 | } 42 | return self; 43 | } 44 | 45 | - (void) prepareForReuse { 46 | [super prepareForReuse]; 47 | } 48 | 49 | static UIFont* system14 = nil; 50 | 51 | + (void)initialize 52 | { 53 | if(self == [VariableHeightCell class]) 54 | { 55 | system14 = [[UIFont systemFontOfSize:14] retain]; 56 | } 57 | } 58 | 59 | - (void)dealloc { 60 | [info release]; 61 | 62 | [super dealloc]; 63 | } 64 | 65 | - (void) drawContentView:(CGRect)rect { 66 | CGContextRef context = UIGraphicsGetCurrentContext(); 67 | 68 | [[UIColor whiteColor] set]; 69 | CGContextFillRect(context, rect); 70 | 71 | NSString* text = [info stringForKey:@"text"]; 72 | 73 | CGFloat widthr = rect.size.width - 10; 74 | 75 | CGSize size = [text sizeWithFont:system14 constrainedToSize:CGSizeMake(widthr, 999999) lineBreakMode:UILineBreakModeTailTruncation]; 76 | 77 | [[UIColor grayColor] set]; 78 | [text drawInRect:CGRectMake(5.0, 5.0, widthr, size.height) withFont:system14 lineBreakMode:UILineBreakModeTailTruncation]; 79 | } 80 | 81 | - (void) updateCellInfo:(NSDictionary*)_info { 82 | self.info = _info; 83 | [self setNeedsDisplay]; 84 | } 85 | 86 | + (CGFloat) heightForCellWithInfo:(NSDictionary*)_info inTable:(UITableView *)tableView { 87 | NSString* text = [_info stringForKey:@"text"]; 88 | 89 | CGFloat widthr = tableView.frame.size.width - 10; 90 | 91 | CGSize size = [text sizeWithFont:system14 constrainedToSize:CGSizeMake(widthr, 999999) lineBreakMode:UILineBreakModeTailTruncation]; 92 | return size.height + 10; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /IOSBoilerplate/VariableHeightExample.h: -------------------------------------------------------------------------------- 1 | // 2 | // VariableHeightExample.h 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface VariableHeightExample : UIViewController 32 | 33 | @property (nonatomic, retain) IBOutlet UITableView* table; 34 | @property (nonatomic, retain) NSArray* results; 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /IOSBoilerplate/VariableHeightExample.m: -------------------------------------------------------------------------------- 1 | // 2 | // VariableHeightExample.m 3 | // IOSBoilerplate 4 | // 5 | // Copyright (c) 2011 Alberto Gimeno Brieba 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "VariableHeightExample.h" 30 | #import "SVProgressHUD.h" 31 | #import "TwitterSearchClient.h" 32 | #import "VariableHeightCell.h" 33 | 34 | @implementation VariableHeightExample 35 | 36 | @synthesize table; 37 | @synthesize results; 38 | 39 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 40 | { 41 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 42 | if (self) { 43 | // Custom initialization 44 | } 45 | return self; 46 | } 47 | 48 | - (void)didReceiveMemoryWarning 49 | { 50 | // Releases the view if it doesn't have a superview. 51 | [super didReceiveMemoryWarning]; 52 | 53 | // Release any cached data, images, etc that aren't in use. 54 | } 55 | 56 | #pragma mark - UITableViewDelegate and DataSource 57 | 58 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 59 | { 60 | return 1; 61 | } 62 | 63 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 64 | { 65 | return [results count]; 66 | } 67 | 68 | // Customize the appearance of table view cells. 69 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 70 | { 71 | static NSString *CellIdentifier = @"Cell"; 72 | 73 | VariableHeightCell *cell = (VariableHeightCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 74 | if (cell == nil) { 75 | cell = [[[VariableHeightCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 76 | } 77 | 78 | NSDictionary* obj = [results objectAtIndex:indexPath.row]; 79 | [cell updateCellInfo:obj]; 80 | return cell; 81 | } 82 | 83 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 84 | NSDictionary* obj = [results objectAtIndex:indexPath.row]; 85 | return [VariableHeightCell heightForCellWithInfo:obj inTable:tableView]; 86 | } 87 | 88 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 89 | { 90 | } 91 | 92 | #pragma mark - View lifecycle 93 | 94 | - (void)viewDidLoad 95 | { 96 | [super viewDidLoad]; 97 | self.title = @"Latest twits about #cats"; 98 | } 99 | 100 | - (void)viewDidUnload 101 | { 102 | [super viewDidUnload]; 103 | // Release any retained subviews of the main view. 104 | // e.g. self.myOutlet = nil; 105 | } 106 | 107 | - (void)viewDidAppear:(BOOL)animated { 108 | [super viewDidAppear:animated]; 109 | 110 | [SVProgressHUD showInView:self.view]; 111 | 112 | [[TwitterSearchClient sharedClient] getPath:@"search" parameters:[NSDictionary dictionaryWithObject:@"cats" forKey:@"q"] success:^(id object) { 113 | [SVProgressHUD dismiss]; 114 | 115 | self.results = [object valueForKey:@"results"]; 116 | [table reloadData]; 117 | } failure:^(NSHTTPURLResponse *response, NSError *error) { 118 | [SVProgressHUD dismissWithError:[error localizedDescription]]; 119 | }]; 120 | } 121 | 122 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 123 | return YES; 124 | } 125 | 126 | - (void)dealloc { 127 | [table release]; 128 | [results release]; 129 | 130 | [super dealloc]; 131 | } 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /IOSBoilerplate/blackArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/blackArrow.png -------------------------------------------------------------------------------- /IOSBoilerplate/blackArrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/blackArrow@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/blueArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/blueArrow.png -------------------------------------------------------------------------------- /IOSBoilerplate/blueArrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/blueArrow@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /IOSBoilerplate/grayArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/grayArrow.png -------------------------------------------------------------------------------- /IOSBoilerplate/grayArrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/grayArrow@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/left.png -------------------------------------------------------------------------------- /IOSBoilerplate/left@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/left@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // IOSBoilerplate 4 | // 5 | // Created by Alberto Gimeno Brieba on 08/09/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, @"MyApplication", nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /IOSBoilerplate/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/right.png -------------------------------------------------------------------------------- /IOSBoilerplate/right@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/right@2x.png -------------------------------------------------------------------------------- /IOSBoilerplate/whiteArrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/whiteArrow.png -------------------------------------------------------------------------------- /IOSBoilerplate/whiteArrow@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/IOSBoilerplate/whiteArrow@2x.png -------------------------------------------------------------------------------- /IOSBoilerplateTests/IOSBoilerplateTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | FooBar-Inc..${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 | -------------------------------------------------------------------------------- /IOSBoilerplateTests/IOSBoilerplateTests.h: -------------------------------------------------------------------------------- 1 | // 2 | // IOSBoilerplateTests.h 3 | // IOSBoilerplateTests 4 | // 5 | // Created by Alberto Gimeno Brieba on 08/09/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface IOSBoilerplateTests : SenTestCase 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /IOSBoilerplateTests/IOSBoilerplateTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // IOSBoilerplateTests.m 3 | // IOSBoilerplateTests 4 | // 5 | // Created by Alberto Gimeno Brieba on 08/09/11. 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import "IOSBoilerplateTests.h" 10 | 11 | @implementation IOSBoilerplateTests 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 IOSBoilerplateTests"); 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /IOSBoilerplateTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | What is IOS Boilerplate 2 | ----------------------- 3 | 4 | Is a base template for iOS projects. 5 | 6 | Please, go to [http://iosboilerplate.com/](http://iosboilerplate.com/) for more documentation and further information. 7 | 8 | Some screenshots: 9 | 10 | ![Demo menu](https://github.com/gimenete/iOS-boilerplate/raw/master/shots/demo-menu.png) 11 | 12 | ![Async cell images demo](https://github.com/gimenete/iOS-boilerplate/raw/master/shots/async-cells.png) 13 | 14 | ![Directions demo](https://github.com/gimenete/iOS-boilerplate/raw/master/shots/directions.png) 15 | 16 | -------------------------------------------------------------------------------- /shots/async-cells.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/shots/async-cells.png -------------------------------------------------------------------------------- /shots/demo-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/shots/demo-menu.png -------------------------------------------------------------------------------- /shots/directions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/shots/directions.png -------------------------------------------------------------------------------- /shots/web-browser.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gimenete/iOS-boilerplate/1c5eace5560f2e2084e98311af0e8b13ba07e4b3/shots/web-browser.png --------------------------------------------------------------------------------