swift - Swift等待比较排序完成
问题描述
通常在 Swift 中,我了解如何等待异步调用完成,然后我可以使用完成处理程序继续完成。
但是,在 Swift 中使用比较器进行排序时,没有迹象表明排序已完成,所以我不知道何时继续。例如,
channels!.sort(comparator: { (c1, c2) -> ComparisonResult in
...
//what do I call here to know that this completed?
}
使用 dispatchgroup.wait() 似乎也不起作用,因为等待也可能在完成之前触发。欢迎提出想法。
谢谢。
解决方案
此调用是同步的,因此您可以将代码放在最后一行之后以使用排序数组。
channels!.sort(comparator: { (c1, c2) -> ComparisonResult in
...
//what do I call here to know that this completed?
}
// channels is sorted over here
推荐阅读
- video - FFMPEG - WEBM 到 AVI 的转换失败
- javascript - React scss模块:子类覆盖作为道具传递的父类
- java - 没有为 Signature 对象选择 BouncyCastleProvider
- coq - 我可以使用 Axiom 命令定义一个等效项吗?
- java - 寻找制作硒刮片产品的解决方案
- python - 模拟或避免 pytest 的 cognito 身份验证和组权限
- ruby-on-rails - 在 Carrierwave 中的多个文件上传中使用数组索引作为拇指文件名
- typescript - 在 NGXS 中解码 SSL 并更新状态
- nginx - 基于当前位置的条件 proxy_pass
- vba - 可以使用 VBA/ADODB 记录集连接从 Access 存储查询中检索“输出”参数吗?