草庐IT

Alamofire-SwiftyJSON

全部标签

ios - 在 Alamofire 请求后,我是否需要 DispatchQueue.main 来更新 UI?

我正在学习有关使用REST/web请求的教程。在本教程中,我们正在开发一个Pokedex应用程序,在该应用程序中,我们使用Alamofire从API中获取Pokemon详细信息,然后在我们的UI中显示该数据。相关代码如下:typealiasDownloadComplete=(Bool)->()//ModelclassfuncdownloadPokemonDetails(completed:@escapingDownloadComplete){Alamofire.request(_pokemonURL).responseJSON{(response)invarsuccess=trueif

ios - Swift:从 SwiftyJson 结果创建结果表

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭7年前。Improvethisquestion由于我是iOS开发的新手,所以我一直在使用Swift,并且非常喜欢了解这门语言。最近我开始考虑安装第三方插件等,我发现了一个名为SwiftyJson(https://github.com/SwiftyJSON/SwiftyJSON)的插件,我已经设法使用这个脚本让它工作:request(.GET,url,parameters:parameters).responseJSON{(req,res,json,e

ios - 使用 Swift 的 Alamofire - "Could not cast value of type ' Swift._SwiftDeferredNSArray' (ox10a75ebb0) 到 'Photomania.PhotoInfo' (0x107ee7b90)。”

运行OSXElCap开发测试版、iOS9.0、Xcode7.0GM我正在关注RayWenderlich教程(http://www.raywenderlich.com/85080/beginning-alamofire-tutorial),但确实遇到了一些问题。在我创建请求路由器之前,我的应用程序无法运行。它构建正确,然后一旦开始加载,我就会在标题中看到调试器短语。构建错误描述为“Thread1:signalSIGABRT”。概述的行是:letimageURL=(photos.objectAtIndex(indexPath.row)as!PhotoInfo).url这是PhotoBrow

ios - 在 Alamofire 2.0 中使用客户端证书

在Alamofire1和Swift1.2上,我使用以下代码发出请求,提交我自己的客户端证书:Alamofire.request(.POST,url!,parameters:params,encoding:.JSON).authenticate(usingCredential:credential).responseJSON{(request,response,JSON,error)in...}在Alamofire和Swift2.0中,我采用了固定证书并使用了我自己的Manager实例。但是服务器报告没有提交有效的证书。letmanager=Manager(configuration:N

swift - Alamofire 快速格式化 POST/PUT 参数

我在iOS(swift)上使用Alamofire时遇到问题:当我尝试使用这样的参数发送请求(在.POST或.PUT中)时:parameters:["description":WhoGives,"images":({container=offerImages;name="563f993e4b00ddad7ed42790_0.jpg";},{container=offerImages;name="563f993e4b00ddad7ed42790_1.jpg";})]它会产生一个像这样的httpBody:description="WhoGives"&images[][container]=“

swift - 将 Alamofire 调用转换为 URLSession

我有一个旧的代码库,我正试图从中迁移出去。网络调用目前使用Alamofire4.0,我正在尝试使用URLSession。我无法弄清楚出了什么问题,这就是我一直在做的事情。我从要发布的路线和参数开始://routetousercreationleturl=...letparams=["user":["first_name":"John","last_name":"Appleseed","email":"john@apple.com","password":"asdfgh"]]这是新旧网络调用://oldnetworkrequestAlamofire.request(url,method:

ios - 如何为 Alamofire 请求全局设置基本 url?

到目前为止,我创建的url请求是这样的:Alamofire.request("https://httpbin.org/room/\(user)/\(password)",method:.patch)每次我创建一个请求时,我都必须将基本url放入每个请求中。我可以以某种方式将基本url声明为全局常量吗?(此处https://httpbin.org/) 最佳答案 你应该使用一个像这样的结构的常量文件//Constants.swiftstructApi{staticletBaseUrl="https://httpbin.org"}然后,在

ios - Swift 3.0,Alamofire 4.0 调用中的额外参数 'method'

我已经阅读了关于这个问题的所有问题this和this.我有以下代码letfullURL=God.getFullURL(apiURL:self.apiUrl)if(getOrPost==God.POST){Alamofire.request(fullURL,method:.POST,AnyObject:self.postData?,encoding:.JSONEncoding.default,headers:nil).responseJSON{responseinself.responseData=response.result.value}}elseif(getOrPost==God.

ios - swift Alamofire : How to validate both a valid request and a valid response code

我们有这个Alamofire错误处理:Alamofire.request(.GET,getUrl("mystuff")).responseData{responseinguardresponse.result.error==nilelse{//Handleerror}}如果无法访问服务器或证书无效等,它会很好地工作。但是如果可以访问服务器但返回404/etc响应代码,则不会触发此错误处理代码。如何将对此用例的支持折叠到此代码中? 最佳答案 response的result属性包含代码,如果它不是nil。否则,您可以获得状态代码。ifl

swift - 为什么 Alamofire 对单元测试的超时预期使用 30 秒?

我正在研究Alamofire如何为NSOperation执行单元测试。这是其他测试使用的基本测试类。知道为什么它使用30秒作为预期的timeout吗?importAlamofireimportFoundationimportXCTestclassBaseTestCase:XCTestCase{lettimeout:NSTimeInterval=30.0funcURLForResource(fileName:String,withExtension:String)->NSURL{letbundle=NSBundle(forClass:BaseTestCase.self)returnbun