DispatchQueue的Swift 3.0未解析标识符 [英] Swift 3.0 unresolved identifier for DispatchQueue

查看:140
本文介绍了DispatchQueue的Swift 3.0未解析标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图找到这个问题几个小时的答案,但仍无济于事。我正在尝试使用以下代码:

I have been trying to find the answer to this for hours now but still no avail. I am trying to use the following code:

func fetchPosts() {
    ref.child("Amore").child("Posts").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
        if let dictionary = snapshot.value as? [String: AnyObject] {
            let postMod = ReviewsPostModel()

            postMod.setValuesForKeysWithDictionary(dictionary)
            self.posts.insert(postMod, atIndex: 0)
        }

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
            self.tableView.reloadData()
        }
    })
}

在Swift 3.0.1中,但是它说DispatchQueue是一个未解析的标识符。我已导入Dispatch,并确保该类指向正确的目标文件。非常感谢任何和所有帮助。

In Swift 3.0.1, but it is saying that "DispatchQueue" is an unresolved identifier. I have imported Dispatch, and made sure that the class was pointed at the right target file. Any and all help is greatly appreciated.

推荐答案

虽然你你正在使用Swift 3.0.1 , 你不是。您正在使用Swift 2.3。因此,没有DispatchQueue这样的东西。你的代码需要这样编写:

Although you say you are using Swift 3.0.1, you are not. You are using Swift 2.3. Thus, there is no such thing as DispatchQueue. Your code needs to be written like this:

let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(0.2 * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
    self.tableView.reloadData()
}

这篇关于DispatchQueue的Swift 3.0未解析标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆