草庐IT

DISPATCH_QUEUE_T

全部标签

Swift:从 dispatch_async 内部返回结果

所以我这里有一段代码不起作用。这是因为它在尝试解包可选值时发现nil。这是因为它在异步方法中被初始化。我的问题是,如何在函数获取结果之前推迟返回函数?structDomain{varname:String?vartld:String?varcombined:String{get{returnself.name!+self.tld!}}varwhoIs:String{get{ifself.whoIs.isEmpty{varresult:String?dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAU

ios - dispatch_async 是否可以中断调用任务

假设我将任务异步分派(dispatch)到队列:{//weareonmainqueuedispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{print("taskB")});print("taskA")//somelongrunningworkprint("taskA")//somelongrunningworkprint("taskA")...}在任何情况下,分派(dispatch)的任务都可以中断从中分派(dispatch)它的任务吗?换句话说,是否会在打印所有“任务A”之前打印“

ios - 使用 performBackgroundTask 将多个核心数据插入分派(dispatch)到 NSPersistentContainer 时合并冲突

我正在试验新的核心数据APINSPersistentContainer,我的印象是内部排队机制会阻止写入事务并发评估,详见堆栈溢出答案NSPersistentContainerconcurrencyforsavingtocoredataThewaythatalotofproshavebeendealingwiththeproblemforalongtime(evenbeforeNSPersistentContainerdidit)wastohaveanoperationqueuetoqueuethewritessothereisonlyonewritegoingonatatime,an

ios - 在 Swift 中,如何从 dispatch_time_t 获取 NSDate?

“Walltime”是GrandCentralDispatch使用的一种鲜为人知的时间格式。苹果在这里谈论它:https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/虽然有些事情确实很方便,但它是一个粘性wicket。很难让它与其他时间格式兼容,这就是我的问题所在。我可以通过将NSDate转换为timespec来制作walltime,然后使用dispatch_walltime:letnow=NSDate().timeIntervalSince1970l

swift - swift 3.0 中的 dispatch_group_async 函数

我的问题是如何在Swift3中正确翻译此函数,因为我注意到有很多关于dispatch_async的文档,但没有任何关于dispatch_group_async的文档>dispatch_group_async(group,dispatch_get_global_queue(QOS_CLASS_USER_INITIATED,0)){[unownedself]in 最佳答案 试试这个:letgroup=DispatchGroup()DispatchQueue.global(qos:.userInitiated).async(group:g

ios - swift 中的 dispatch_block_t 相当于什么?

我有一些我想理解的objective-c代码,以便在swift中执行相同的操作:dispatch_block_tadjustTooltipVisibility=^{self.tooltipView.alpha=_tooltipVisible?1.0:0.0;self.tooltipTipView.alpha=_tooltipVisible?1.0:0.0;};到目前为止,关于dispatch_block_t我能找到的所有信息是它在swift的dispatch_after中用作闭包。所以我能理解,但我不明白它在objective-c中的用法,以及如何将这段代码转换为swift代码

ios - 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因 : 'Duplicate states in queue'

我正在开发一个使用UISlideViewController的项目。我知道这可能是一个重复的问题,但之前关于这个主题的帖子都没有帮助我。正如我设法理解的那样,我有一个特定的问题。我的应用程序在此block上崩溃。我以前读过,将所有与UI相关的工作都放在主线程中很重要。这是代码:pageViewController.setViewControllers([viewController],direction:direction,animated:animated,completion:{completedindispatch_async(dispatch_get_main_queue())

ios - 具有父类(super class)和子类的 Swift 协议(protocol)扩展方法分派(dispatch)

我发现了一个有趣的行为,它看起来像是一个错误......基于以下文章描述的行为:https://medium.com/ios-os-x-development/swift-protocol-extension-method-dispatch-6a6bf270ba94http://nomothetis.svbtle.com/the-ghost-of-swift-bugs-future当我添加SomeSuperclass而不是直接采用协议(protocol)时,输出不是我所期望的。protocolTheProtocol{funcmethod1()}extensionTheProtocol{

ios - swift ,dispatch_group_wait 不等待

我正在尝试使用grandcentraldispatch来等待文件完成下载,然后再继续。这个问题是这个问题的衍生问题:Swift(iOS),waitingforallimagestofinishdownloadingbeforereturning.我只是想找出如何让dispatch_group_wait(或类似的)真正等待,而不是在下载完成之前继续。请注意,如果我使用NSThread.sleepForTimeInterval而不是调用downloadImage,它会等待得很好。我错过了什么?classImageDownloader{varupdateResult=AdUpdateResu

c++ priority_queue用法 入门必看 超详细

1、priority_queue的作用priority_queue即优先级队列,它的使用场景很多,它底层是用大小根堆实现的,可以用log(n)的时间动态地维护数据的有序性。适用于许多场景,比如简化哈夫曼树算法、dijkstra算法等等priority_queue是不允许随机访问,只能访问队列首部的元素,也只能对首部元素进行出队,下面进行学习它的基本用法2、priority_queue的定义头文件#include基本定义方法:基本定义默认是使用大顶堆的,即队首总是最大的元素priority_queue容器名如:priority_queueint>q;//储存int型数据priority_queu