How can I log each request/response using Alamofire?

There’s a sweet little pod for this: https://github.com/konkab/AlamofireNetworkActivityLogger Add this to your podfile: pod ‘AlamofireNetworkActivityLogger’, ‘~> 2.0′ In your AppDelegate: import AlamofireNetworkActivityLogger Then in your didFinishLaunchingWithOptions, add this: NetworkActivityLogger.shared.level = .debug NetworkActivityLogger.shared.startLogging() EDIT: I’ve actually encountered crashes with this in production. To be on the safe side, use “build flags” to only use this in … Read more

Proper usage of the Alamofire’s URLRequestConvertible

Great questions. Let’s break down each one individually. What is the proper usage of URLRequestConvertible in real world API? The URLRequestConvertible protocol is a lightweight way to ensure a given object can create a valid NSURLRequest. There’s not really a strict set of rules or guidelines that exist forcing you to use this protocol in … Read more

AlamoFire asynchronous completionHandler for JSON request

This is a really good question. Your approach is perfectly valid. However, Alamofire can actually help you streamline this even more. Your Example Code Dispatch Queue Breakdown In you example code, you are jumping between the following dispatch queues: NSURLSession dispatch queue TaskDelegate dispatch queue for validation and serializer processing Main dispatch queue for calling … Read more

POST request with a simple string in body with Alamofire

Your example Alamofire.request(.POST, “http://mywebsite.example/post-request”, parameters: [“foo”: “bar”]) already contains “foo=bar” string as its body. But if you really want string with custom format. You can do this: Alamofire.request(.POST, “http://mywebsite.example/post-request”, parameters: [:], encoding: .Custom({ (convertible, params) in var mutableRequest = convertible.URLRequest.copy() as NSMutableURLRequest mutableRequest.HTTPBody = “myBodyString”.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) return (mutableRequest, nil) })) Note: parameters should not … Read more

Uploading file with parameters using Alamofire

Here is a simple function that requires the target upload url, parameters, and imageData and returns the URLRequestConvertible and NSData that Alamofire.upload requires to upload an image with parameters. // this function creates the required URLRequestConvertible and NSData we need to use Alamofire.upload func urlRequestWithComponents(urlString:String, parameters:Dictionary<String, String>, imageData:NSData) -> (URLRequestConvertible, NSData) { // create url … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)