草庐IT

async-upload

全部标签

swift - 在 Alamofire.upload swift 3 中没有更多上下文,表达式类型不明确

更新后的Alamofire4.0.0没有提到如何将Httpmethod和Httpheaders与multipartFormData一起上传。这就是为什么我用谷歌搜索并在那个stackoverflow问题中找到了解决方案。但问题是我做了与该答案相同的操作,然后收到以下错误消息并且构建失败。请帮我解决一下。Typeofexpressionisambiguouswithoutmorecontext这是我的代码:letURL=try!URLRequest(url:Config.imageUploadURL,method:.post,headers:headers)Alamofire.uploa

ios - 在 dispatch_async 中正确引用 self

如何在swift闭包中正确引用self?dispatch_async(dispatch_get_main_queue()){self.popViewControllerAnimated(true)}我得到错误:无法将表达式的类型“Void”转换为类型“UIViewController!”我随机尝试过:dispatch_async(dispatch_get_main_queue()){()self.popViewControllerAnimated(true)}它奏效了。不确定extra()的作用!有人愿意解释吗?谢谢! 最佳答案 这

ios - 我需要将我的 Alamofire 调用包装在 dispatch_async 中吗?

funcauthenticate(completion:(success:Bool)->Void){letqos=Int(QOS_CLASS_USER_INITIATED.value)dispatch_async(dispatch_get_global_queue(qos,0)){()->VoidinAlamofire.request(.POST,CONSTANTS.Domain+"/accounts",parameters:["":""]).responseJSON{(req,res,json,error)indispatch_async(dispatch_get_main_queu

swift - 如何取消 Alamofire.upload

我正在通过Alamofire.upload将图像作为多部分数据上传到服务器。与Alamofire.request不同,它不返回Request对象,我通常用它来取消请求。但是能取消上传这种耗时的请求是很合理的。Alamofire对此有哪些选择? 最佳答案 使用UploadingMultiPartFormData来自Alamofire自述文件的示例:Alamofire.upload(.POST,"https://httpbin.org/post",multipartFormData:{multipartFormDatainmultipa

swift - 在 Swift 中使用 Dispatch_Async 更新 UI

在我的代码中,我有一个简单的for循环,它循环100次并嵌套for循环以产生延迟。延迟之后,我正在通过dispatch_async更新UI中的进度View元素。但是,我无法更新UI。有谁知道为什么UI不更新?注意:下面的打印语句用于验证for循环是否正确循环。foriin0.. 最佳答案 三个观察,两个基本的,一个更高级一点:除非循环本身在另一个线程上运行,否则您的循环将无法更新该主线程中的UI。因此,您可以将其分派(dispatch)到某个后台队列。在Swift3中:DispatchQueue.global(qos:.utilit

grand-central-dispatch - 对自己使用 dispatch_async

我在将Objective-C代码移植到Swift时遇到过几次这个问题。假设我有以下代码:dispatch_async(dispatch_get_main_queue()){self.hostViewController?.view.addSubview(self.commandField)}这将导致错误,强调整个dispatch_async调用,提供:Couldnotfindmember'addSubview'我认为这是一个尚未正确实现的错误,因为如果我将addSubview调用放在dispatch_asyncblock之外,项目构建良好。最初我认为它可能与在block中捕获self有

c# - 为什么 async/await 允许从 List 到 IEnumerable 的隐式转换?

我刚刚研究了async/await并发现了一些有趣的东西。看看下面的例子://1)ok-obviouspublicTask>GetAll(){IEnumerabledoctors=newList{newDoctorDto()};returnTask.FromResult(doctors);}//2)ok-obviouspublicasyncTask>GetAll(){IEnumerabledoctors=newList{newDoctorDto()};returnawaitTask.FromResult(doctors);}//3)ok-notsoobviouspublicasyncT

c# - 在 C# 5 中将 WPF 事件处理程序声明为 'async' 的意义

想象一个WPF代码隐藏事件处理程序:在C#4中,您可以将处理程序声明为:privatevoidOnButtonClick(objectsender,RoutedEventArgse){...}在C#5中,您可以声明一个async处理程序privateasyncvoidOnButtonClick(objectsender,RoutedEventArgse){...}那么WPF用这个做什么呢?搜索了几分钟没有找到任何结果。似乎可以在await语句之后执行UI更新。这是否意味着任务在Dispatcher线程上继续?如果Task引发错误,它会通过WPFDispatcher引发,还是仅通过Tas

c# - RestSharp ASYNC client.ExecuteAsync<T> () 工作示例

谁能帮我修改下面的代码:client.ExecuteAsync(request,response=>{Console.WriteLine(response.Content);});基本上我想使用上面的ExecuteAsync方法但不想打印而是返回response.Content给调用者。有什么简单的方法可以做到这一点吗?我试过了,但没用:publicTExecute(RestRequestrequest)whereT:new(){varclient=newRestClient();client.BaseUrl=BaseUrl;client.Authenticator=newHttpBa

c# - 为什么不使用 async/await 关键字时异步单元测试会失败?

根据thisdiscussion,下面两种方法应该没有区别:publicasyncTaskFoo(){awaitDoSomethingAsync();}publicTaskFoo(){returnDoSomethingAsync();}实际上,对于非常简单的方法来说,不async/await关键字的调用似乎是首选,因为它们可以消除一些开销。然而,这显然并不总是适用于单元测试。MSTest[TestClass]publicclassAsyncTest{[TestMethod]publicasyncTaskTest1(){awaitTask.Delay(0);}[TestMethod]pu