alamofire

I won't be able to return a value with Alamofire in Swift

荒凉一梦 提交于 2019-11-27 19:30:37
问题 The current code I'm having doens't seem to return anything, I can't find out what is causing the issue. func getQuests(category: NSString, count: Int) -> NSArray { var quests = NSArray() Alamofire.request(.GET, apiUrlString, parameters: ["category": category, "count": count]) .responseJSON { (request, response, json, error) in dispatch_async(dispatch_get_main_queue(), { quests = json as NSArray }) } println(quests) #=> () return quests } Does anybody know how to solve the issue I'm having?

Handle timeout with Alamofire

吃可爱长大的小学妹 提交于 2019-11-27 18:59:32
Is it possible to add timeout handler for Alamofire request? In my project I use Alamofire this way: init() { let configuration = NSURLSessionConfiguration.defaultSessionConfiguration() configuration.timeoutIntervalForRequest = 30 self.alamofireManager = Alamofire.Manager(configuration: configuration) } func requestAuthorizationWithEmail(email:NSString, password:NSString, completion: (result: RequestResult) -> Void) { self.alamofireManager!.request(.POST, "myURL", parameters:["email": email, "password":password]) .responseJSON { response in switch response.result { case .Success(let JSON): /

how to use Alamofire with custom headers

故事扮演 提交于 2019-11-27 17:14:42
I am just starting to take a look at Mattt's wonderful new Alamofire swift networking library and am not quite sure how one would use it with custom headers. The code i am trying to convert from AFNetworking to Alamofire is this: let request = NSMutableURLRequest(URL: url) request.setValue(authorizationToken, forHTTPHeaderField:"Authorization") Nikola Lajic According to the official documentation, modifying the session configuration is not recommended: This is not recommended for Authorization or Content-Type headers. Instead, use URLRequestConvertible and ParameterEncoding, respectively. So

Extra argument 'method' in call

我是研究僧i 提交于 2019-11-27 17:04:49
问题 Getting error while calling Alamofire request method in the latest version(4.0.0). The syntax is: Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: .JSON, headers: [:]) the type of requestParam is [String:Any] 回答1: I got the issue, I have to use JSONEncoding.default instead of .JSON, so the new syntax is Alamofire.request(urlString,method: .post, parameters: requestParams, encoding: JSONEncoding.default, headers: [:]) 回答2: I can only refer you to: https://github

Using Alamofire within a Playground

假如想象 提交于 2019-11-27 16:07:20
问题 I'm new to iOS development and using Xcode and I'm having trouble getting Alamofire to work within a Playground. There's some functionality I'd like to test out for proof of concept but the library is not linked to the Playground and I've tried getting it to play nicely. I have Alamofire set up to work within an iOS (not in a Playground) project before the installation instructions in the Github Alamofire repo were recently updated. Any suggestions on how to get Alamofire to import properly

Swift and using class extension

孤街醉人 提交于 2019-11-27 15:03:46
I don't understand why programmers use the extension keyword in their class implementation. You can read in other topics that code is then more semantically separated and etc. But when I work with my own code, it feels clearer to me to use // MARK - Something . Then when you use methods list (ctrl+6) in Xcode, everything is seen at first look. In Apple documentation you can read: “Extensions add new functionality to an existing class, structure, or enumeration type.” So why not write my own code directly inside my own class? Unlike when I want to extend functionality of some foreign class,

alamofire.error Code=-6006 \"JSON could not be serialized

走远了吗. 提交于 2019-11-27 15:03:36
Been working on this for a bit with no success. I have a function that goes to a UIButton solely to perform alamofire calls to my rails api which uses all JSON. I'm using Swift 2, Alamofire 3, XCode 7 & Rails 4 for my api which is deployed to Heroku I keep getting this error when I fire off the function : alamofire.error Code=-6006 "JSON could not be serialized. Input data was nil or zero length. Here is my code : @IBAction func Save(sender: AnyObject) { let postsEndpoint: String = "https://APIURL" let parameters = [ "users": [ "name": "James McHarty", "avatar": "Some binary data", "post": [

“No such module 'Alamofire'” Xcode won't recognize Alamofire framework

ⅰ亾dé卋堺 提交于 2019-11-27 14:25:07
I realize that the same error was asked in other questions (like here ), but their solutions are not working for me. I keep getting a build failure in my app: "No such module 'Alamofire'". I followed the cocoadocs installation instructions ( here ) for installing Alamofire and it still is not working. I made sure everything has the same deployment target. Embedded Binaries and Frameworks Here's my podfile text. source 'https://github.com/CocoaPods/Specs.git' platform :ios, ‘9.2’ use_frameworks! target 'MyApp' do pod 'Alamofire', '~> 3.0' end target 'MyAppTests' do end target 'MyAppUITests' do

Swift - Dynamic UITableViewCell size based on image aspect ratio

十年热恋 提交于 2019-11-27 14:12:56
问题 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

Swift closure with Alamofire

牧云@^-^@ 提交于 2019-11-27 14:07:47
I am making API calls to a server. I am leveraging Alamofire to handle this. I'm trying to create a function that uses Alamofire's GET function to return an object based on a custom class that holds the various outputs provided by this GET function. It's not clear to me the way in which to do this. Here's my custom class that will hold details about the response: import Foundation class ResponsePackage { var success = false var response: AnyObject? = nil var error: NSError? = nil } In another class I have the following function: func get(apiEndPoint: NSString) -> ResponsePackage { let