草庐IT

apply_async

全部标签

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 - 在 Swift 中使用 Dispatch_Async 更新 UI

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

ios - tableviewcell "binary operator ' = =' cannot be applied to operands of type cell and nil"的解析/快速问题

我在使用Xcode6.3beta时遇到Parse/Swift的问题overridefunctableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath,object:PFObject)->PFTableViewCell{varcell=tableView.dequeueReusableCellWithIdentifier("cell",forIndexPath:indexPath)as!secTableViewCellifcell==nil{cell=secTableViewCell(style:U

swift - 使用增量运算符会产生构建错误 "swift Unary operator '++' cannot be applied to an operand of type ' Int'"

在BasicOperators部分,Swift编程语言指南指出++是有效的运算符:“MorecomplexexamplesincludethelogicalANDoperator&&(asinifenteredDoorCode&&passedRetinaScan)andtheincrementoperator++i,whichisashortcuttoincreasethevalueofiby1.”摘自:AppleInc.“TheSwiftProgrammingLanguage”。电子书。https://itun.es/gb/jEUH0.l但是,在Playground上尝试这样做时;i

ios - 如何在 Swift 中编写通用的 apply() 函数?

有什么方法可以使以下内容在Swift3中正常工作?letbutton=UIButton().apply{$0.setImage(UIImage(named:"UserLocation"),for:.normal)$0.addTarget(self,action:#selector(focusUserLocation),for:.touchUpInside)$0.translatesAutoresizingMaskIntoConstraints=false$0.backgroundColor=UIColor.black.withAlphaComponent(0.5)$0.layer.co

Swift 协议(protocol)错误 : 'weak' cannot be applied to non-class type

Protocols和class-boundProtocols有什么区别,我们应该在Swift中使用哪一个?protocolA:class{...}protocolA{...}当协议(protocol)未定义为:class时尝试添加weak委托(delegate)时出现错误:protocolA{...}weakvardelegate:A给出错误:'weak'cannotbeappliedtonon-classtype或'weak'mustnotbeappliedtonon-class-bound'A';consideraddingaprotocolconformancethathasac

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有

iOS 10.3 : NSStrikethroughStyleAttributeName is not rendered if applied to a sub range of NSMutableAttributedString

如果应用范围不是整个字符串范围,则不会呈现作为属性添加到NSMutableAttributedString实例的删除线(单、双、...)。这发生在使用addAttribute(_name:String,value:Any,range:NSRange),insert(_attrString:NSAttributedString,atloc:Int),append(_attrString:NSAttributedString),...在早期的iO​​S10.3测试版中被Apple破坏,在10.3final中没有修复。信用:https://openradar.appspot.com/3103

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