Does Alamofire store the cookies automatically?

Yes! Alamofire is basically a wrapper around NSURLSession. Its manager uses a default NSURLSessionConfiguration by calling defaultSessionConfiguration(). As its github page says under Advanced Usage section: Alamofire is built on NSURLSession and the Foundation URL Loading System. To make the most of this framework, it is recommended that you be familiar with the concepts and … Read more

Download File Using Alamofire 4.0 (Swift 3)

I used to use this statements: let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory) Alamofire.download( url, method: .get, parameters: parameters, encoding: JSONEncoding.default, headers: nil, to: destination).downloadProgress(closure: { (progress) in //progress closure }).response(completionHandler: { (DefaultDownloadResponse) in //here you able to access the DefaultDownloadResponse //result closure }) For more details read more in Alamofire docs about Migration to 4.0:

Swift variable name with ` (backtick)

According to the Swift documentation : To use a reserved word as an identifier, put a backtick (`)before and after it. For example, class is not a valid identifier, but `class` is valid. The backticks are not considered part of the identifier; `x` and x have the same meaning. In your example, default is a … Read more

How to convert a Swift object to a dictionary

I must disagree with @Darko. In Swift 2, use protocol oriented programming and the simple reflection offered by Mirror class : protocol JSONAble {} extension JSONAble { func toDict() -> [String:Any] { var dict = [String:Any]() let otherSelf = Mirror(reflecting: self) for child in otherSelf.children { if let key = child.label { dict[key] = child.value … Read more

How to load image in swift using Alamofire

As authors mention in Alamofire README.md: When should I use AFNetworking? UIKit extensions, such as asynchronously loading images to UIImageView So answer to your question : So is AFNetworking is better for this task? Yes! But if still want to use vanilla Alamofire project, you can fetch image this way: Alamofire.request(.GET, “https://robohash.org/123.png”).response { (request, response, … Read more

AlamoFire does not respect timeout interval

Are you sure that the 4 seconds timeout is not enforced? I have created an experiment: let center = NSNotificationCenter.defaultCenter() var alamoFireManager : Alamofire.Manager? let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForRequest = 4 // seconds configuration.timeoutIntervalForResource = 4 self.alamoFireManager = Alamofire.Manager(configuration: configuration) self.alamoFireManager!.request(.POST, “http://oznet.go.ro/iDorMobile/ConfigServer/api.php/timeout/2”, parameters: nil).responseJSON { (req, res, json, error) in println(“First json \(json)”) println(“First error … Read more

How to check internet connection in alamofire?

For swift 5 and Alamofire 5.4.4 ,I created a swift class called Connectivity . Use NetworkReachabilityManager class from Alamofire and configure the isConnectedToInternet() method as per your need. import Foundation import Alamofire class Connectivity { class func isConnectedToInternet() -> Bool { return NetworkReachabilityManager()?.isReachable ?? false } } Usage: if Connectivity.isConnectedToInternet() { print(“Yes! internet is available.”) … Read more

AlamoFire Download in Background Session

Update Based on this amazing tutorial, I have put together an example project available on GitHub. It has an example for background session management. According to Apple’s URL Loading System Programming Guide: In both iOS and OS X, when the user relaunches your app, your app should immediately create background configuration objects with the same … Read more

Cannot install Alamofire in new Xcode Project. “No Such module Alamofire”

Make sure you haven’t added any files from Alamofire to your project except for the Alamofire.xcodeproj Here is step by step instruction: Download and unarchive Alamofire Copy the root folder of Alamofire to any subfolder of your project. Libs, for example. Drag and drop Alamofire.xcodeproj to your Xcode project Open project settings of your project, … Read more