appjam 0.1.8.6 → 0.1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. data/lib/appjam.rb +1 -1
  2. data/lib/appjam/generators/blank.rb +133 -0
  3. data/lib/appjam/generators/help.rb +5 -3
  4. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
  5. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  6. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  7. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
  8. data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
  9. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
  10. data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
  11. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
  12. data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
  13. data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
  14. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
  15. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
  16. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
  17. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
  18. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
  19. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
  20. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
  21. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
  22. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  23. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
  24. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
  25. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  26. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
  27. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
  28. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
  29. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
  30. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
  31. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
  32. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
  33. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
  34. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
  35. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
  36. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
  37. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
  38. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
  39. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
  40. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
  41. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
  42. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
  43. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
  44. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
  45. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
  46. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
  47. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
  48. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
  49. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  50. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  51. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
  52. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
  53. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
  54. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
  55. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
  56. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
  57. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  58. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  59. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  60. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  61. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
  62. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
  63. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
  64. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
  65. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
  66. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
  67. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
  68. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
  69. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
  70. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
  71. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
  72. data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
  73. data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
  74. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
  75. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
  76. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
  77. data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
  78. data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
  79. data/lib/appjam/generators/templates/resources/Default.png +0 -0
  80. data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
  81. data/lib/appjam/generators/templates/resources/contents.tt +4 -0
  82. data/lib/appjam/version.rb +1 -1
  83. metadata +462 -326
  84. data/test/helper.rb +0 -132
  85. data/test/test_model_generator.rb +0 -28
  86. data/test/test_project_generator.rb +0 -38
@@ -0,0 +1,89 @@
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 <Foundation/Foundation.h>
24
+ #import "AFHTTPRequestOperation.h"
25
+
26
+ #import <Availability.h>
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
+ ## Use With AFHTTPClient
39
+
40
+ When `AFXMLRequestOperation` is registered with `AFHTTPClient`, the response object in the success callback of `HTTPRequestOperationWithRequest:success:failure:` will be an instance of `NSXMLParser`. On platforms that support `NSXMLDocument`, you have the option to ignore the response object, and simply use the `responseXMLDocument` property of the operation argument of the callback.
41
+ */
42
+ @interface AFXMLRequestOperation : AFHTTPRequestOperation
43
+
44
+ ///----------------------------
45
+ /// @name Getting Response Data
46
+ ///----------------------------
47
+
48
+ /**
49
+ An `NSXMLParser` object constructed from the response data.
50
+ */
51
+ @property (readonly, nonatomic, strong) NSXMLParser *responseXMLParser;
52
+
53
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
54
+ /**
55
+ 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.
56
+ */
57
+ @property (readonly, nonatomic, strong) NSXMLDocument *responseXMLDocument;
58
+ #endif
59
+
60
+ /**
61
+ Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
62
+
63
+ @param urlRequest The request object to be loaded asynchronously during execution of the operation
64
+ @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.
65
+ @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.
66
+
67
+ @return A new XML request operation
68
+ */
69
+ + (instancetype)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
70
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
71
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure;
72
+
73
+
74
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
75
+ /**
76
+ Creates and returns an `AFXMLRequestOperation` object and sets the specified success and failure callbacks.
77
+
78
+ @param urlRequest The request object to be loaded asynchronously during execution of the operation
79
+ @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.
80
+ @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response 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.
81
+
82
+ @return A new XML request operation
83
+ */
84
+ + (instancetype)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
85
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
86
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure;
87
+ #endif
88
+
89
+ @end
@@ -0,0 +1,166 @@
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 <Availability.h>
26
+
27
+ static dispatch_queue_t xml_request_operation_processing_queue() {
28
+ static dispatch_queue_t af_xml_request_operation_processing_queue;
29
+ static dispatch_once_t onceToken;
30
+ dispatch_once(&onceToken, ^{
31
+ af_xml_request_operation_processing_queue = dispatch_queue_create("com.alamofire.networking.xml-request.processing", DISPATCH_QUEUE_CONCURRENT);
32
+ });
33
+
34
+ return af_xml_request_operation_processing_queue;
35
+ }
36
+
37
+ @interface AFXMLRequestOperation ()
38
+ @property (readwrite, nonatomic, strong) NSXMLParser *responseXMLParser;
39
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
40
+ @property (readwrite, nonatomic, strong) NSXMLDocument *responseXMLDocument;
41
+ #endif
42
+ @property (readwrite, nonatomic, strong) NSError *XMLError;
43
+ @end
44
+
45
+ @implementation AFXMLRequestOperation
46
+ @synthesize responseXMLParser = _responseXMLParser;
47
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
48
+ @synthesize responseXMLDocument = _responseXMLDocument;
49
+ #endif
50
+ @synthesize XMLError = _XMLError;
51
+
52
+ + (instancetype)XMLParserRequestOperationWithRequest:(NSURLRequest *)urlRequest
53
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success
54
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure
55
+ {
56
+ AFXMLRequestOperation *requestOperation = [(AFXMLRequestOperation *)[self alloc] initWithRequest:urlRequest];
57
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
58
+ if (success) {
59
+ success(operation.request, operation.response, responseObject);
60
+ }
61
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
62
+ if (failure) {
63
+ failure(operation.request, operation.response, error, [(AFXMLRequestOperation *)operation responseXMLParser]);
64
+ }
65
+ }];
66
+
67
+ return requestOperation;
68
+ }
69
+
70
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
71
+ + (instancetype)XMLDocumentRequestOperationWithRequest:(NSURLRequest *)urlRequest
72
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success
73
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure
74
+ {
75
+ AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest];
76
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, __unused id responseObject) {
77
+ if (success) {
78
+ NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
79
+ success(operation.request, operation.response, XMLDocument);
80
+ }
81
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
82
+ if (failure) {
83
+ NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument];
84
+ failure(operation.request, operation.response, error, XMLDocument);
85
+ }
86
+ }];
87
+
88
+ return requestOperation;
89
+ }
90
+ #endif
91
+
92
+
93
+ - (NSXMLParser *)responseXMLParser {
94
+ if (!_responseXMLParser && [self.responseData length] > 0 && [self isFinished]) {
95
+ self.responseXMLParser = [[NSXMLParser alloc] initWithData:self.responseData];
96
+ }
97
+
98
+ return _responseXMLParser;
99
+ }
100
+
101
+ #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
102
+ - (NSXMLDocument *)responseXMLDocument {
103
+ if (!_responseXMLDocument && [self.responseData length] > 0 && [self isFinished]) {
104
+ NSError *error = nil;
105
+ self.responseXMLDocument = [[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error];
106
+ self.XMLError = error;
107
+ }
108
+
109
+ return _responseXMLDocument;
110
+ }
111
+ #endif
112
+
113
+ - (NSError *)error {
114
+ if (_XMLError) {
115
+ return _XMLError;
116
+ } else {
117
+ return [super error];
118
+ }
119
+ }
120
+
121
+ #pragma mark - NSOperation
122
+
123
+ - (void)cancel {
124
+ [super cancel];
125
+
126
+ self.responseXMLParser.delegate = nil;
127
+ }
128
+
129
+ #pragma mark - AFHTTPRequestOperation
130
+
131
+ + (NSSet *)acceptableContentTypes {
132
+ return [NSSet setWithObjects:@"application/xml", @"text/xml", nil];
133
+ }
134
+
135
+ + (BOOL)canProcessRequest:(NSURLRequest *)request {
136
+ return [[[request URL] pathExtension] isEqualToString:@"xml"] || [super canProcessRequest:request];
137
+ }
138
+
139
+ - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
140
+ failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure
141
+ {
142
+ #pragma clang diagnostic push
143
+ #pragma clang diagnostic ignored "-Warc-retain-cycles"
144
+ self.completionBlock = ^ {
145
+ dispatch_async(xml_request_operation_processing_queue(), ^(void) {
146
+ NSXMLParser *XMLParser = self.responseXMLParser;
147
+
148
+ if (self.error) {
149
+ if (failure) {
150
+ dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{
151
+ failure(self, self.error);
152
+ });
153
+ }
154
+ } else {
155
+ if (success) {
156
+ dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{
157
+ success(self, XMLParser);
158
+ });
159
+ }
160
+ }
161
+ });
162
+ };
163
+ #pragma clang diagnostic pop
164
+ }
165
+
166
+ @end
@@ -0,0 +1,78 @@
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 <Foundation/Foundation.h>
24
+ #import "AFImageRequestOperation.h"
25
+
26
+ #import <Availability.h>
27
+
28
+ #if __IPHONE_OS_VERSION_MIN_REQUIRED
29
+ #import <UIKit/UIKit.h>
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. Any previous image request for the receiver will be cancelled. 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.
38
+
39
+ @discussion By default, URL requests have a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set 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. Any previous image request for the receiver will be cancelled. 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 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. Any previous image request for the receiver will be cancelled. 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 If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is executed.
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
+ /**
72
+ Cancels any executing image request operation for the receiver, if one exists.
73
+ */
74
+ - (void)cancelImageRequestOperation;
75
+
76
+ @end
77
+
78
+ #endif
@@ -0,0 +1,184 @@
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 <Foundation/Foundation.h>
24
+ #import <objc/runtime.h>
25
+
26
+ #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
27
+ #import "UIImageView+AFNetworking.h"
28
+
29
+ @interface AFImageCache : NSCache
30
+ - (UIImage *)cachedImageForRequest:(NSURLRequest *)request;
31
+ - (void)cacheImage:(UIImage *)image
32
+ forRequest:(NSURLRequest *)request;
33
+ @end
34
+
35
+ #pragma mark -
36
+
37
+ static char kAFImageRequestOperationObjectKey;
38
+
39
+ @interface UIImageView (_AFNetworking)
40
+ @property (readwrite, nonatomic, strong, setter = af_setImageRequestOperation:) AFImageRequestOperation *af_imageRequestOperation;
41
+ @end
42
+
43
+ @implementation UIImageView (_AFNetworking)
44
+ @dynamic af_imageRequestOperation;
45
+ @end
46
+
47
+ #pragma mark -
48
+
49
+ @implementation UIImageView (AFNetworking)
50
+
51
+ - (AFHTTPRequestOperation *)af_imageRequestOperation {
52
+ return (AFHTTPRequestOperation *)objc_getAssociatedObject(self, &kAFImageRequestOperationObjectKey);
53
+ }
54
+
55
+ - (void)af_setImageRequestOperation:(AFImageRequestOperation *)imageRequestOperation {
56
+ objc_setAssociatedObject(self, &kAFImageRequestOperationObjectKey, imageRequestOperation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
57
+ }
58
+
59
+ + (NSOperationQueue *)af_sharedImageRequestOperationQueue {
60
+ static NSOperationQueue *_af_imageRequestOperationQueue = nil;
61
+ static dispatch_once_t onceToken;
62
+ dispatch_once(&onceToken, ^{
63
+ _af_imageRequestOperationQueue = [[NSOperationQueue alloc] init];
64
+ [_af_imageRequestOperationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
65
+ });
66
+
67
+ return _af_imageRequestOperationQueue;
68
+ }
69
+
70
+ + (AFImageCache *)af_sharedImageCache {
71
+ static AFImageCache *_af_imageCache = nil;
72
+ static dispatch_once_t oncePredicate;
73
+ dispatch_once(&oncePredicate, ^{
74
+ _af_imageCache = [[AFImageCache alloc] init];
75
+ });
76
+
77
+ return _af_imageCache;
78
+ }
79
+
80
+ #pragma mark -
81
+
82
+ - (void)setImageWithURL:(NSURL *)url {
83
+ [self setImageWithURL:url placeholderImage:nil];
84
+ }
85
+
86
+ - (void)setImageWithURL:(NSURL *)url
87
+ placeholderImage:(UIImage *)placeholderImage
88
+ {
89
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
90
+ [request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
91
+
92
+ [self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
93
+ }
94
+
95
+ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
96
+ placeholderImage:(UIImage *)placeholderImage
97
+ success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
98
+ failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
99
+ {
100
+ [self cancelImageRequestOperation];
101
+
102
+ UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
103
+ if (cachedImage) {
104
+ if (success) {
105
+ success(nil, nil, cachedImage);
106
+ } else {
107
+ self.image = cachedImage;
108
+ }
109
+
110
+ self.af_imageRequestOperation = nil;
111
+ } else {
112
+ self.image = placeholderImage;
113
+
114
+ AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
115
+ [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
116
+ if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
117
+ if (success) {
118
+ success(operation.request, operation.response, responseObject);
119
+ } else if (responseObject) {
120
+ self.image = responseObject;
121
+ }
122
+
123
+ if (self.af_imageRequestOperation == operation) {
124
+ self.af_imageRequestOperation = nil;
125
+ }
126
+ }
127
+
128
+ [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
129
+ } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
130
+ if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
131
+ if (failure) {
132
+ failure(operation.request, operation.response, error);
133
+ }
134
+
135
+ if (self.af_imageRequestOperation == operation) {
136
+ self.af_imageRequestOperation = nil;
137
+ }
138
+ }
139
+ }];
140
+
141
+ self.af_imageRequestOperation = requestOperation;
142
+
143
+ [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];
144
+ }
145
+ }
146
+
147
+ - (void)cancelImageRequestOperation {
148
+ [self.af_imageRequestOperation cancel];
149
+ self.af_imageRequestOperation = nil;
150
+ }
151
+
152
+ @end
153
+
154
+ #pragma mark -
155
+
156
+ static inline NSString * AFImageCacheKeyFromURLRequest(NSURLRequest *request) {
157
+ return [[request URL] absoluteString];
158
+ }
159
+
160
+ @implementation AFImageCache
161
+
162
+ - (UIImage *)cachedImageForRequest:(NSURLRequest *)request {
163
+ switch ([request cachePolicy]) {
164
+ case NSURLRequestReloadIgnoringCacheData:
165
+ case NSURLRequestReloadIgnoringLocalAndRemoteCacheData:
166
+ return nil;
167
+ default:
168
+ break;
169
+ }
170
+
171
+ return [self objectForKey:AFImageCacheKeyFromURLRequest(request)];
172
+ }
173
+
174
+ - (void)cacheImage:(UIImage *)image
175
+ forRequest:(NSURLRequest *)request
176
+ {
177
+ if (image && request) {
178
+ [self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)];
179
+ }
180
+ }
181
+
182
+ @end
183
+
184
+ #endif