alamofire

Append object to a variable

☆樱花仙子☆ 提交于 2019-12-20 06:05:10
问题 I'm trying to append an object to an array of objects. var products: [Product] = [] init() { Alamofire.request(.GET, Urls.menu).responseJSON { request in if let json = request.result.value { let data = JSON(json) for (_, subJson): (String, JSON) in data { let product = Product(id: subJson["id"].int!, name: subJson["name"].string!, description: subJson["description"].string!, price: subJson["price"].doubleValue) print(product) self.products.append(product) } } } self.products.append(Product(id

“too many HTTP redirects” while using Alamofire Upload Multipart Form Data

狂风中的少年 提交于 2019-12-20 04:16:36
问题 I'm using Alamofire 3 and encountered this: [Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects" UserInfo={NSUnderlyingError=0x15eb422d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1007 "(null)"}, NSErrorFailingURLStringKey=URL omitted, NSErrorFailingURLKey= URL omitted, NSLocalizedDescription= too many HTTP redirects} while calling this method: upload(.POST, kTaskSubmitImageUrl, multipartFormData: { multipartFormData in multipartFormData.appendBodyPart(data:

POST requests in Alamofire Parameter Encoding returning GET responses

半腔热情 提交于 2019-12-20 04:15:17
问题 I'm trying to make a Route Builder in swift using Alamofire (3.0) and I have succeded for all my GET requests, but when I try to make a POST request, for example, I still get the same responses of the GET method. My API Routes are: /users //GET -> return list of users /users //POST -> create new user with the parameters sent When I use Postman everything works fine. Here is my Router code: import Foundation import Alamofire enum UserRouter: URLRequestConvertible{ static let baseURL = NSURL

AlamofireImage how to clean memory and cache

空扰寡人 提交于 2019-12-20 04:14:03
问题 I use Alamofire and AlamofireImage in my app for get data and photos. Alamofire.request(.GET, URLString, encoding: .JSON) .authenticate(user: user, password: password) .responseJSON() { (response) -> Void in if let jsonResult = response.result.value { if jsonResult.count > 0 { ... let photo_url = jsonResult[index]["Photo_url"] as! String Alamofire.request(.GET, photo_url) .authenticate(user: user_photo, password: password_photo) .responseImage { response in if let image = response.result

Swift - HTTP load failed (error code: -1005 [4:-4]), while uploading image through alamofire.

泪湿孤枕 提交于 2019-12-20 03:43:26
问题 I am a newbie to iOS and using Alamofire to upload images. The code I have written is as follows: let image = imageView.image let imgData = UIImageJPEGRepresentation(image!, 0.2)! let headers: HTTPHeaders = [ "x-access-token": "######", "Accept": "application/json" ] let parameters = ["profile_picture": "kinza"] let url = try! URLRequest(url: URL(string:"######")!, method: .post, headers: headers) Alamofire.upload(multipartFormData: { multipartFormData in multipartFormData.append(imgData,

XCTest Unit Test data response not set in test after viewDidLoad

牧云@^-^@ 提交于 2019-12-20 03:23:35
问题 I'm trying to write Unit Tests and currently I try to test a viewController which received data in viewDidLoad() , the data is set after a alamofire request. The problem is, that in my test function when I check the array which should be filled with 10 elements after the successful request, is 0. I've checked if viewDidLoad() in the test is not executed, but it should be, because when I just add elements to another array, which is outside the request, the specific test works. I guess, it has

Apple Watch “No such module 'Alamofire'”

百般思念 提交于 2019-12-20 03:16:25
问题 Alamofire has been working fine for an iPhone only project. I DID THE MANUAL INSTALL OF ALAMOFIRE - NOT COCOA PODS Now I have added a watch app target following these steps - https://developer.apple.com/library/content/documentation/General/Conceptual/WatchKitProgrammingGuide/ConfiguringYourXcodeProject.html#//apple_ref/doc/uid/TP40014969-CH2-SW1IIm "import Alamofire" works fine on the iPhone's view controller but when I try to add it to one of the code files in the " Extension" Folder the

Cannot install Alamofire 4.0 in Xcode 8.0 Using CocoaPods

a 夏天 提交于 2019-12-19 21:25:52
问题 I need to upgrade one project to Swift 3.0, that has some libraries by Cocodpods. So, I've removed all links related with Cocoapods and recreate pod file using pod init and upgrade some version of library such as AlamorFire. But pod install said [!] Unable to satisfy the following requirements: - `Alamofire (~> 4.0)` required by `Podfile` None of your spec sources contain a spec satisfying the dependency: `Alamofire (~> 4.0)`. You have either: * out-of-date source repos which you can update

Cannot install Alamofire 4.0 in Xcode 8.0 Using CocoaPods

徘徊边缘 提交于 2019-12-19 21:25:44
问题 I need to upgrade one project to Swift 3.0, that has some libraries by Cocodpods. So, I've removed all links related with Cocoapods and recreate pod file using pod init and upgrade some version of library such as AlamorFire. But pod install said [!] Unable to satisfy the following requirements: - `Alamofire (~> 4.0)` required by `Podfile` None of your spec sources contain a spec satisfying the dependency: `Alamofire (~> 4.0)`. You have either: * out-of-date source repos which you can update

WebService API Method in Swift 3 and Swift 4?

穿精又带淫゛_ 提交于 2019-12-19 11:36:53
问题 I am new to Swift iOS and i want to create a separate method in separate class(like NSObject ) of web services so that i can use it in any ViewController and parse any type of JSON response using NSURLSession and Alamofire . Could someone help me. 回答1: class WebRequester: NSObject { static let shared = WebRequester() let session = URLSession.shared func request(urlStr:String, parameter:String, token:String? = nil, callback:@escaping (_ result:NSDictionary?, error:Error?) -> Void) { let url =