This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @objc public enum RequestMethod: NSInteger { | |
| case OPTIONS = 0, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT | |
| } | |
| @objc public enum RequestParameterEncoding: NSInteger { | |
| case URL, URLEncodedInURL, JSON | |
| } | |
| public class AlamofireWrapper: NSObject { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class BodyPart: NSObject { | |
| var data: NSData | |
| var name: String | |
| var fileName: String? | |
| var mimeType: String? | |
| init(data: NSData, name: String) { | |
| self.data = data | |
| self.name = name | |
| super.init() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AlamofireWrapper: NSObject { | |
| // MARK: - Request Methods | |
| /** | |
| Creates a request using the shared manager instance for the specified method, URL string, parameters, and | |
| parameter encoding. | |
| - parameter method: The HTTP method. | |
| - parameter URLString: The URL string. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class func parseResponse(response: Response<AnyObject, NSError>, success: (request: NSURLRequest?, response: NSHTTPURLResponse?, json: [NSObject: AnyObject]?) -> (), | |
| failure: (request: NSURLRequest?, response: NSHTTPURLResponse?, error: NSError?) -> ()) { | |
| switch (response.result) { | |
| case .Success(let json): | |
| if let json = json as? [NSObject: AnyObject] { | |
| success(request: response.request, response: response.response, json: json) | |
| } else { | |
| success(request: response.request, response: response.response, json: [NSObject: AnyObject]()) | |
| } | |
| case .Failure(let error): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [AlamofireWrapper request:RequestMethodGET URLString:@"http://something.com" parameters:nil encoding:RequestParameterEncodingURL headers:nil success:^(NSURLRequest * _Nullable request, NSHTTPURLResponse * _Nullable response, NSDictionary * _Nullable json) { | |
| NSLog(@"Success"); | |
| // Get the required information from the response JSON | |
| } failure:^(NSURLRequest * _Nullable request, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) { | |
| NSLog(@"Failure"); | |
| }]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: MultipartFormData | |
| /** | |
| Creates an upload request using the shared manager instance for the specified method and URL string. | |
| - parameter method: The HTTP method. | |
| - parameter URLString: The URL string. | |
| - parameter headers: The HTTP headers. `nil` by default. | |
| - parameter multipartFormData: The closure used to append body parts to the `MultipartFormData`. | |
| - parameter success: Block to be called in case of successful execution of the request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [AlamofireWrapper upload:RequestMethodPOST :@"http://myaddress.com" headers:nil multipartFormData:^NSArray<BodyPart *> * _Nonnull { | |
| return @[[[BodyPart alloc] initWithData:[NSData dataWithContentsOfFile:@"myVeryLargeFile.jpg"] name:@"picture"]]; | |
| } success:^(NSURLRequest * _Nullable request, NSHTTPURLResponse * _Nullable response, NSDictionary * _Nullable json) { | |
| NSLog(@"Success"); | |
| } failure:^(NSURLRequest * _Nullable request, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error) { | |
| NSLog(@"Failure"); | |
| }]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private class func parseResponse(response: Response<NSData, NSError>, success: (request: NSURLRequest?, response: NSHTTPURLResponse?, json: [NSObject: AnyObject]?) -> (), | |
| failure: (request: NSURLRequest?, response: NSHTTPURLResponse?, error: NSError?) -> ()) { | |
| switch (response.result) { | |
| case .Success(let data): | |
| if let json = try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments), parsed = json as? [NSObject: AnyObject] { | |
| success(request: response.request, response: response.response, json: parsed) | |
| } else { | |
| success(request: response.request, response: response.response, json: [NSObject: AnyObject]()) | |
| } | |
| case .Failure(let error): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyTest: NSObject { | |
| private var identifier: String = "myIdentifier" | |
| var defaultContent: [String] | |
| init(withItem item: String) { | |
| self.defaultContent = [item] | |
| } | |
| class func fetchInfo(success: (info: [AnyObject: AnyObject]) -> (), failure: ((error: NSError?) -> ())? ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyTest: NSObject { | |
| private var identifier = "myIdentifier" | |
| var defaultContent: [String] | |
| init(withItem item: String) { | |
| defaultContent = [item] | |
| } | |
| class func fetchInfo(success: (info: [AnyObject: AnyObject]?) -> (), failure: ((error: NSError?) -> ())? ) { |
OlderNewer