草庐IT

dispatch-after

全部标签

ios - Swift 3 中的 DISPATCH_QUEUE_T

这个问题在这里已经有了答案:HowtocreatedispatchqueueinSwift3(15个答案)关闭6年前。我正在编写我的第一个Swift3,但我遇到了以下错误dispatch_queue_t在swift中不可用。varqueue:dispatch_queue_t?vardebugPrint=falsepublicinit(){letuuid=NSUUID().uuidStringletqueueLabel="tomlogger-queue-"+uuidqueue=dispatch_queue_create(queueLabel,DISPATCH_QUEUE_SERIAL)}

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 - 火力地堡 : How to removeObserver(withHandle:) after observeSingleEvent()?

我将Firebase数据库与swift结合使用。当我使用databaseReference.observe(...)进行观察时,我可以轻松地从DatabaseReference中删除观察者:databaseHandle=databaseReference.observe(.value,with:{(snapshot)in...},withCancel:{(error)in...})...databaseReference.removeObserver(withHandle:databaseHandle)我的问题是当我使用databaseReference.observeSingleEv

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 - 应用程序 :openURL:options: not called after opening universal link

我已经使用BranchSDK设置了通用链接。链接正确打开应用程序,并且application:continueUserActivity:restorationHandler:被调用,但不是`application:openURL:options:'funcapplication(_app:UIApplication,openurl:URL,options:[UIApplicationOpenURLOptionsKey:Any]=[:])->Bool{Branch.getInstance().application(app,open:url,options:options)returnt

Swift/CloudKit : After record changed, 上传触发器 "Service Record Changed"

我正在尝试将CKReference添加到云工具包中的记录,但尝试不断触发“服务记录已更改”。从我的println显示的控制台消息(下面的控制台消息和代码),我正在上传带有0个引用的记录,然后当我附加引用时,我看到尝试上传带有1个引用的记录。然后我收到错误。据我所知,不应触发“服务记录已更改”,因为引用列表中的值已更改(记录有一个完整的额外字段)。即使我在开发模式,我手动为ReferenceList创建了key-value字段,因为当referencelist为空时,第一次上传的记录不包括该字段(上传空数组会导致另一个错误)。我将在控制台消息之后按照相关性顺序包含代码(您将能够看到大部分

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代码