alamofire

Getting JSON by using Alamofire and decode - Swift 4

人走茶凉 提交于 2019-12-13 14:01:35
问题 I have an API and I also want to get request. But I try to using JSONDecoder to convert data type and I failed. I don't know how to decode this Json like following data. I want to take json["response"] contents setting my User struct. Have any suggestion to me? Thanks. Error Domain=NSCocoaErrorDomain Code=4865 "No value associated with key id ("id")." UserInfo={NSCodingPath=( ), NSDebugDescription=No value associated with key id ("id").} This is JSON Data: { "status": "success", "response": {

How to run Alamofire library

不羁的心 提交于 2019-12-13 13:50:27
问题 I downloaded the alamofire library and opened the iOS Example.xcodeproj, but it won't run. In import Alamofire , when i command press it it gives message that Alamofire symbol not found. Alamofire.framework is showing red. How to tackle this problem? 回答1: I had the same problem. So I removed all files related to Alamofire from project folder and also removed the framework from the project. Then I again added Alamofire framework as per its guide and that ran successfully. I suggest you to do

PHP upload from iOS using Alamofire

筅森魡賤 提交于 2019-12-13 12:56:43
问题 I'm trying to upload 3 images to the server from iOS to my PHP service. For some reason the folder remains empty after posting, but the rest of the data goes through and gets persisted into mysql. My iOS code: Alamofire.upload(.POST, urlString, multipartFormData: { multipartFormData in if (firstPhoto != nil) { if let firstImageData = UIImageJPEGRepresentation(firstImage!, 0.6) { print("uploading image"); multipartFormData.appendBodyPart(data: firstImageData, name: "firstImage", fileName:

How to load view after Alamofire finished its job?

a 夏天 提交于 2019-12-13 10:29:11
问题 My Issue: I am trying to load data from Server, through Alamofire , before SubViewController Load its view. After writing the code, I failed to solve the problem of Async Feature of Alamofire. The view is always be loaded in the SubViewController before Alamofire finished its job. Part Of My Code: ParentViewController: Leading the way to SubViewController through PrepareForSegue() . override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier ==

{ error = “invalid_request”; “error_description” = “Required parameter is missing: grant_type”; } In swift

左心房为你撑大大i 提交于 2019-12-13 10:08:22
问题 I am trying with this but every time I will get { error = "invalid_request"; "error_description" = "Required parameter is missing: grant_type"; } Request String: let headers = [ "Content-Type" : "application/x-www-form-urlencoded"] let urlString = "https://accounts.google.com/o/oauth2/token?" Alamofire.request(urlString, method: .post, parameters: ["grant_type":"authorization_code","code":"4/FAOYR1mQo1lN1Gdg9jDnigwZ8RP76NUrqPbYZlMCSP28","client_id":"387376833747

ios call function in background mode

夙愿已清 提交于 2019-12-13 09:41:02
问题 my app running in the background and I want to take the html data from the web server every 60 second. (with alamofire or nsurlconnection etc..) but I could not find sample code associated with it. Is it possible to do something like this. updated every minute I want to do. applications running in the background mode, updateServer function I want to call every 60 second note: with background fetch methot not working every minute. func application(application: UIApplication,

Variable keeps returning nil - Swift iOS

 ̄綄美尐妖づ 提交于 2019-12-13 09:08:28
问题 I'm using Alamofire to Parse JSON data. Everything is working fine in below mentioned code except 'var id: JSON?' variable though it's updating just fine but it keeps returning nil at a point (at bottom). I need to put this variable inside filter closure. class GreetingObjectHandler { var greetings: [Greeting] = [] var id: JSON? //this variable init(filename: String) { Alamofire.request(.GET, "http://localhost:2403/users/me") .responseJSON { (req, res, data, error) in if(error != nil) { NSLog

Defining function error using generics

巧了我就是萌 提交于 2019-12-13 08:47:15
问题 Here's the code: extension Alamofire.Request { public func responseObject<T: ResponseJSONObjectSerializable> (completionHandler: (NSURLRequest?, NSHTTPURLResponse?, Result<T> -> Void) -> Self { //Error1: expected ',' separator //Error2: expected parameter type following ':' ... ) } I'm using Swift 2.0, Alamofire 3.0, and SwiftyJSON. 回答1: Problem solved: there's a mistake of parenthesis in the code, the ) should be place behind result<T> rather than the end of the function. I thought it was

Alamofire not working in xcode 7

本小妞迷上赌 提交于 2019-12-13 07:38:02
问题 I am not getting any sort of error when puthing the import statement at the top of the file. Alamofire, from what I can tell, is recognized by xcode. It is when I try and access code from Alamofire when I run into problems. When I begin to type Alamo, the only auto complete I code I can use is "Alamofireversionnumber" and nothing more. For clarification I am using xcode 7 and swift 2. 来源: https://stackoverflow.com/questions/33685768/alamofire-not-working-in-xcode-7

Swift 3- Update UI from main thread

不羁岁月 提交于 2019-12-13 06:54:07
问题 I wanted to load data in background thread and update tableview/UI on main thread. Based on what's indicated here about threading, I was wondering if the code below is the way to go about it. I'm trying to load more data as user scrolls to a specific index and wanted to make sure the UI is not freezing due to threading. Thank you! func loadMore () { guard !self.reachedEndOfItems else { return } self.offset = self.offset! + 10 print("load more offset: \(self.offset)") var start = 0 var end = 0