alamofire

Swift variable name with ` (backtick)

笑着哭i 提交于 2019-11-29 13:10:28
I was browsing Alamofire sources and found variable which name is backtick escaped in this source file open static let `default`: SessionManager = { let configuration = URLSessionConfiguration.default configuration.httpAdditionalHeaders = SessionManager.defaultHTTPHeaders return SessionManager(configuration: configuration) }() However in places where variable is used there are no backticks. What's the purpose of backticks? 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`

'Method' is ambiguous for type lookup in this context, Error in Alamofire

旧巷老猫 提交于 2019-11-29 13:06:53
I am using Alamofire for network handling in swift and run into one weird error. It seems like we can't pass Method enum as parameter. [Error is on Method parameter] private func apiRequest(method: Method, url: String, apiData: [String : AnyObject], completion:(finished: Bool, response: AnyObject?) ->Void) { Alamofire.request(method, url, parameters: apiData).responseJSON{ response in if let JSON = response.result.value { completion(finished: true, response: JSON) } else { completion(finished: false, response:nil) } } } harpreetSingh You have to specify the module from which to lookup object

Setting snippet data for youtube upload via REST API using Swift

怎甘沉沦 提交于 2019-11-29 12:58:53
I'm able to successfully upload a video to youtube via their REST API using the following code: func postVideoToYouTube(token: String, callback: Bool -> Void){ let headers = ["Authorization": "Bearer \(token)"] let path = NSBundle.mainBundle().pathForResource("video", ofType: "mp4") let videodata: NSData = NSData.dataWithContentsOfMappedFile(path!)! as! NSData upload( .POST, "https://www.googleapis.com/upload/youtube/v3/videos?part=id", headers: headers, multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(data: videodata, name: "video", fileName: "video.mp4", mimeType:

Dictionary is not convertible to Void

戏子无情 提交于 2019-11-29 12:23:59
Hi guys I've been searching the net without much luck but I'm trying to get around Alamofires asynchronous nature. I'm trying to return the JSON response as a dictionary but Xcode is giving me "Dictionary is not convertible to 'Void'" func homePageDetails(userName:String) -> (Dictionary<String,AnyObject>){ let username = userName let hompePageDetails = Alamofire.request(.GET, "http://example.com/API/Bunch/GetHomePageDetails/\(username)/").responseJSON{(request, response, JSON, error) in print(JSON) var test = JSON as Dictionary<String,AnyObject> return test } } Any help would be greatly

Using retryWhen to update tokens based on http error code

落爺英雄遲暮 提交于 2019-11-29 11:31:44
问题 I found this example on How to refresh oauth token using moya and rxswift which I had to alter slightly to get to compile. This code works 80% for my scenario. The problem with it is that it will run for all http errors, and not just 401 errors. What I want is to have all my other http errors passed on as errors, so that I can handle them else where and not swallow them here. With this code, if I get a HttpStatus 500 , it will run the authentication code 3 times which is obviously not what I

URL Encode Alamofire GET params with SwiftyJSON

一世执手 提交于 2019-11-29 08:45:28
I am trying to have Alamofire send the following parameter in a GET request but it's sending gibberish: filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //www.example.com/example?filters={"$and":[{"name":{"$bw":"duke"},"country":"gb"}]} //Obviously URL encoded This is my code: let jsonObject = ["$and":[["name":["$bw":string], "country":"gb"]]] let json = JSON(jsonObject) print(json) outputs { "$and" : [ { "name" : { "$bw" : "duke" }, "country" : "gb" } ] } This is my params request: let params = ["filters" : json.rawValue, "limit":"1", "KEY":"my_key"] This is what AlamoFire is sending

How to decode a JSON property with different types? [duplicate]

只愿长相守 提交于 2019-11-29 08:37:45
This question already has an answer here: What Is Preventing My Conversion From String to Int When Decoding Using Swift 4’s Codable? 1 answer I have a JSON { "tvShow": { "id": 5348, "name": "Supernatural", "permalink": "supernatural", "url": "http://www.episodate.com/tv-show/supernatural", "description": "Supernatural is an American fantasy horror television series created by Eric Kripke. It was first broadcast on September 13, 2005, on The WB and subsequently became part of successor The CW's lineup. Starring Jared Padalecki as Sam Winchester and Jensen Ackles as Dean Winchester, the series

Load data from json using UIPickerView

这一生的挚爱 提交于 2019-11-29 08:24:19
My Current View Controller is like this import UIKit import Alamofire class ViewController: UIViewController , UIPickerViewDelegate, UIPickerViewDataSource{ @IBOutlet var venuePicker : UIPickerView? var result = [String:String]() var resultArray = [String]() override func viewDidLoad() { self.venuePicker?.delegate = self Alamofire.request(.POST, "http://example.com/xxx/xx/xx").responseJSON() { (request, response, jsonData, error) in var venues = JSON(jsonData!) let d = venues.dictionaryValue for (k, v) in venues { self.result[k] = v.arrayValue[0].stringValue } self.resultArray = self.result

Waiting for Alamofire in Unit Tests

点点圈 提交于 2019-11-29 07:50:44
I'm trying to write a method where a data object (Realm) refreshes it's properties using Alamofire. But I can't figure out how to unit test it. import Alamofire import RealmSwift import SwiftyJSON class Thingy: Object { // some properties dynamic var property // refresh instance func refreshThingy() { Alamofire.request(.GET, URL) .responseJSON { response in self.property = response["JSON"].string } } } In my unit tests, I want to test that the Thingy can refresh from server properly. import Alamofire import SwiftyJSON import XCTest @testable import MyModule class Thingy_Tests: XCTestCase {

Alamofire clear all cookies

筅森魡賤 提交于 2019-11-29 07:45:44
问题 I need the user to be able to log out. When they log in now, a cookie gets saved automatically, that works fine. But I want to clear all cookies. NSURLCache.sharedURLCache().removeAllCachedResponses() This does not work 回答1: You can remove all the cookies specifically stored for an URL like this (Swift 3): let cstorage = HTTPCookieStorage.shared if let cookies = cstorage.cookies(for: url) { for cookie in cookies { cstorage.deleteCookie(cookie) } } 来源: https://stackoverflow.com/questions