alamofire

How do I access a nested JSON value using Alamofire and SwiftyJSON?

半城伤御伤魂 提交于 2019-12-01 09:38:58
问题 I am trying to access nested JSON results using swiftyJSON and Alamofire. My print value is nill and I believe I am not doing this correctly. What should my parameters be? I am trying to get the quote value located at http://quotes.rest/qod.json func getAPI() { Alamofire.request(.GET, "http://quotes.rest/qod.json", parameters: ["contents": "quotes"]) .responseJSON { response in if let JSON = response.result.value { print(JSON["quote"]) } } } 回答1: In your JSON quotes is an array so if you want

How do I return something from AlamoFire?

强颜欢笑 提交于 2019-12-01 08:44:51
问题 import Foundation import Alamofire import UIKit import SwiftyJSON class APIClient: UIViewController { let loggedIn = false struct Constants{ static let Domain = "http://gogogo.com" } func authenticate() -> Bool{ println("Authenticating") if let access_token = FBSDKAccessToken.currentAccessToken().tokenString { let parameters = [ "access_token": access_token ] Alamofire.request(.POST, Constants.Domain+"/accounts", parameters: parameters).responseJSON { (req, res, json, error) in if(error !=

Using Alamofire and multipart/form-data

痴心易碎 提交于 2019-12-01 08:26:26
I'm unable to approach the API that has been offered to me in the proper way for it to give me the response I'm looking for. I've been using Swift and Alamofire for a while but this is the first time I've to upload images using multipart/form-data. I'm able to upload images using Postman but I'm unable to get the same message send out by my application using the Alamofire framework. My Swift code: func postFulfilWish(wish_id: Int, picture : UIImage, completionHandler: ((AnyObject?, ErrorType?) -> Void)) { var urlPostFulfilWish = Constant.apiUrl; urlPostFulfilWish += "/wishes/";

Alamofire, Objectmapper, Realm: Nested Objects

风流意气都作罢 提交于 2019-12-01 07:32:12
I'm using Alamofire, Objectmapper, Realm and everything is working beside one thing: I can't map nested objects. class Voting: Object, Mappable { dynamic var votingID: String = "" dynamic var question: String = "" var votingOptions = List<VotingOption>() required convenience init?(_ map: Map) { self.init() } func mapping(map: Map) { votingID <- map["id"] question <- map["question"] votingOptions <- map["votingOptions"] } override class func primaryKey() -> String { return "votingID" } } class VotingOption: Object, Mappable{ dynamic var optionID: String = "" dynamic var text: String = ""

Using Alamofire and multipart/form-data

冷暖自知 提交于 2019-12-01 07:03:35
问题 I'm unable to approach the API that has been offered to me in the proper way for it to give me the response I'm looking for. I've been using Swift and Alamofire for a while but this is the first time I've to upload images using multipart/form-data. I'm able to upload images using Postman but I'm unable to get the same message send out by my application using the Alamofire framework. My Swift code: func postFulfilWish(wish_id: Int, picture : UIImage, completionHandler: ((AnyObject?, ErrorType?

Live search throttle in Swift 3

血红的双手。 提交于 2019-12-01 06:55:24
I'm trying to live search at my PHP API with Swift. Until now i've done this thing. var filteredData = [Products]() func getSearch(completed: @escaping DownloadComplete, searchString: String) { let parameters: Parameters = [ "action" : "search", "subaction" : "get", "product_name" : searchString, "limit" : "0,30" ] Alamofire.request(baseurl, method: .get, parameters: parameters).responseJSON { (responseData) -> Void in if((responseData.result.value) != nil) { let result = responseData.result if let dict = result.value as? Dictionary<String, AnyObject>{ if let list = dict["products_in_category"

Get JSON result with GET request and parameters with Alamofire

泄露秘密 提交于 2019-12-01 06:29:20
This is my url String with paramaters. http://api.room2shop.com/api/product/GetProducts?categoryId=22&filter=2&pageNumber=1 through which I am getting my JSON data. I have AFWrapper.swift file in which I have defined function for GETrequest. import UIKit import Alamofire import SwiftyJSON class AFWrapper: NSObject { class func requestGETURL(strURL: String, params : [String : AnyObject]?, success:(JSON) -> Void, failure:(NSError) -> Void) { Alamofire.request(.GET, strURL, parameters: params, encoding: ParameterEncoding.JSON).responseJSON { (responseObject) -> Void in print(responseObject) if

Xcode 9 fails to build Swift 4 project with pod

懵懂的女人 提交于 2019-12-01 05:53:38
When attempting to build my Swift 4 project in Xcode 9 beta 2, some code signing error occurs after which the build of my app is discontinued. The error that is shown in Xcode: /usr/bin/codesign --force --sign - --preserve-metadata=identifier,entitlements '/Users/nickgaens/Library/Developer/Xcode/DerivedData/Emprova_Swift-bbvmoytlhlbqpueyftstselvwhdj/Build/Products/Debug-iphonesimulator/Emprova GPS Swift.app/Frameworks/Alamofire.framework' /Users/nickgaens/Library/Developer/Xcode/DerivedData/Emprova_Swift-bbvmoytlhlbqpueyftstselvwhdj/Build/Products/Debug-iphonesimulator/Emprova GPS Swift.app

Swift 2.0 soap request with Alamofire send xml parameters

跟風遠走 提交于 2019-12-01 05:37:04
I want to do a request to this web service example: http://www.holidaywebservice.com//HolidayService_v2/HolidayService2.asmx?wsdl I need to send one parameter "countryCode". I don't know how can i do that with alamofire. And how i get the response to parse the xml result. This is how i did in postman, but i want to know how do the same in swift. Thanks for your help. Try it Will make a POST request URL = http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl The Parameters are sent to the encoding section encoding: .Custom => Created a mutbleRequest a. You can take directly

Certificate Invalid Issue with Alamofire 4.0

强颜欢笑 提交于 2019-12-01 05:35:18
I am trying to consume web services for my iOS app over https. The web server uses a self signed certificate. When consuming the web service, I get the error “certificate is Invalid”. FAILURE: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “portal” which could put your confidential information at risk." I know the best practise is to fix this at the server side to enable a trusted root CA. But as this is a temporary development environment, we are using a self signed certificate. Since this is