alamofire

Swift - Dynamic UITableViewCell size based on image aspect ratio

送分小仙女□ 提交于 2019-11-30 05:27:01
I'm trying to create dynamically sized UITableViewCells, changing the height based on the aspect ratio of an image downloaded from a server. For example, if an image's height is double its width, I want the UITableViewCell's height to be double the screen width so that the image can take up the full width of the screen and maintain the aspect ratio. What I've tried to do is add constraints to the cell and use UITableViewAutomaticDimension to calculate the height, but the problem I'm facing is that I cannot know the aspect ratio of the image until it is downloaded, and therefore the cells start

AlamoFire Ignore Cache-Control Headers

£可爱£侵袭症+ 提交于 2019-11-30 05:26:59
Is it possible to ignore cache-control headers when performing a request/handling the response with AlamoFire? Currently I am making a request as follows, and the server is returning large cache-control headers, when in fact we need to ignore them. Alamofire.request(.GET, url).responseJSON { (_, _, result) in // Do something I know the correct solution is to modify the server response, but this is not feasible at this time. Also, there are other requests where I do want to honor the cache-control headers, so ideally I would a solution that does not involve changing a global configuration of

How do I use JSON arrays with Alamofire parameters?

 ̄綄美尐妖づ 提交于 2019-11-30 05:22:37
问题 I'm having a bit of trouble structuring my parameters so that our server API would be able to read it as valid JSON. Alamofire uses parameters like this in swift language let parameters : [String: AnyObject] = [ "string": str "params": HOW I INSERT A VALID JSON ARRAY HERE ] The problem is that AnyObject does not seem to accept JSON so how would I send / create a structure like this with swift? { "string": str, "params" : [ { "param1" : "something", "param2" : 1, "param3" : 2, "param" : false

Alamofire POST request with progress

时间秒杀一切 提交于 2019-11-30 05:15:05
问题 I'm using Alamofire to do a POST request. As this POST request can take a while and I want to keep track of the progress and display it as a ProgressView. Alamofire.request(.POST, ApiLink.create_post, parameters: parameters, encoding: .JSON) .progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in println("ENTER .PROGRESSS") println("\(totalBytesRead) of \(totalBytesExpectedToRead)") self.progressView.setProgress(Float(totalBytesRead) / Float(totalBytesExpectedToRead),

Alamofire Accept and Content-Type JSON

只谈情不闲聊 提交于 2019-11-30 05:06:36
I'm trying to make a GET request with Alamofire in Swift. I need to set the following headers: Content-Type: application/json Accept: application/json I could hack around it and do it directly specifying the headers for the request, but I want to do it with ParameterEncoding , as is suggested in the library. So far I have this: Alamofire.request(.GET, url, encoding: .JSON) .validate() .responseJSON { (req, res, json, error) in if (error != nil) { NSLog("Error: \(error)") println(req) println(res) } else { NSLog("Success: \(url)") var json = JSON(json!) } } Content-Type is set, but not Accept .

How to pause/resume/cancel my download request in Alamofire

好久不见. 提交于 2019-11-30 03:45:25
I am downloading a file using Alamofire download with progress but i have no idea how to pause / resume / cancel the specific request. @IBAction func downloadBtnTapped() { Alamofire.download(.GET, "http://httpbin.org/stream/100", destination: destination) .progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) in println(totalBytesRead) } .response { (request, response, _, error) in println(response) } } @IBAction func pauseBtnTapped(sender : UIButton) { // i would like to pause/cancel my download request here } Keep a reference to the request created in downloadBtnTapped with a

Populating tableview cells from JSON with Alamofire (Swift 2)

余生长醉 提交于 2019-11-30 03:15:05
问题 I have the following code. import UIKit import Alamofire class CheHappyTableViewController: UITableViewController, NSURLConnectionDelegate { var happyHours = [HappyHour]() override func viewDidLoad() { super.viewDidLoad() //Load the cell elements loadHappyHourElements() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func loadHappyHourElements(){ let testhappyhour:HappyHour = HappyHour(title: "TEST", image:

Cocoapods + Cannot load underlying module for 'x'

大憨熊 提交于 2019-11-30 02:32:44
I am running XCode 7, Swift 2.0, iOS 9. I want to install Alamofire in my project using Cocoapods. I have done the following: gem install cocoapods pod setup pod init Updated Podfile to: # Uncomment this line to define a global platform for your project # platform :ios, '9.0' use_frameworks! target 'JSONeg' do pod 'Alamofire', :branch => 'swift-2' end Then I installed the pod: pod install And I added the following to ViewController.swift import Alamofire This raises the following error: Cannot load underlying module for 'Alamofire' I tested with another pod and it raised the same error, so I

How to send POST request with both parameter and body for JSON data in Swift 3 using Alamofire 4?

允我心安 提交于 2019-11-30 02:24:37
Postman api url added below. Present code : let baseUrl = "abc.com/search/" let param = [ "page":"1", "size":"5", "sortBy":"profile_locality" ] let headers = [ "Content-Type": "application/json" ] Alamofire.SessionManager.default.request("\(baseUrl)field", method: .post,parameters: param, encoding: JSONEncoding.default, headers: headers).responseJSON { response in print(response.request ?? "no request") // original URL request if(response.response?.statusCode != nil){ print("done") if self.checkResponse(response.response!.statusCode){ let json = JSON(data: response.data!) //print("at_LeadStop

How can I log each request/response using Alamofire?

牧云@^-^@ 提交于 2019-11-29 22:47:59
Is there a way to log each request / response using Alamofire (something similar to AFNetworkActivityLogger) ? I am aware of Printable, DebugPrintable and Output (cURL) but they are not quite what I am looking for. Something like this might be what you were looking for: extension Request { public func debugLog() -> Self { #if DEBUG debugPrint(self) #endif return self } } Usage: Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"]) .debugLog() .response {…} If you want to print all responses, you could write your own response method, similar to the responseObject()