【问题标题】:What is the difference between question mark and exclamation point in swift?swift中问号和感叹号有什么区别?
【发布时间】:2016-07-29 03:40:46
【问题描述】:

给定这样一段代码:

func downloadImage() {
    // if image is not downloaded yet, get it
    // 1
    if (post?.image.value == nil) {
        // 2
        post?.imageFile!.getDataInBackgroundWithBlock { (data: NSData?, error: NSError?) -> Void in

            if let data = data {

                let image = UIImage(data: data, scale:1.0)!
                // 3
                self.post!.image.value = image
            }
        }
    }
}

如果我转帖,有什么区别?到!

另外,我怎么会尝试做!我得到一个:

EXC_BAD_INSTRUCTION,但是当我使用 ?我没有收到错误消息,但我尝试加载的屏幕直到刷新才加载?

想法?

【问题讨论】:

  • 作为异步方法,您需要获取主队列来更新 UI
  • @LeoDabus 您能否进一步扩展一下以及如何做到这一点?
  • dispatch_async(dispatch_get_main_queue()) { \\ update UI code }
  • @LeoDabus 很棒的作品很棒,谢谢!

标签: ios swift


【解决方案1】:

dispatch_async(dispatch_get_main_queue()) {\更新UI代码}

【讨论】:

  • 这是对问题的回答还是尝试编辑?请解释此代码的作用或编辑问题。
  • @JJJ:看起来他们抄袭了this comment,他们回复了很棒的作品,非常棒,谢谢。大概这是某种答案。
猜你喜欢
  • 2014-07-30
  • 1970-01-01
  • 1970-01-01
  • 2013-07-12
  • 2014-07-23
  • 1970-01-01
  • 2022-07-26
  • 1970-01-01
相关资源
最近更新 更多