swift 3中的dispatch_once的新语法是什么?旧版本如下。
var token: dispatch_once_t = 0 func test() { dispatch_once(&token) { } }
这里是changes到libdispatch的Swift 3。
从
doc:
Dispatch The free function dispatch_once is no longer available in
Swift. In Swift,you can use lazily initialized globals or static
properties and get the same thread-safety and called-once guarantees
as dispatch_once provided. Example:let myGlobal = { … global contains initialization in a call to a closure … }() _ = myGlobal // using myGlobal will invoke the initialization code only the first time it is used.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。