swift中的问号和感叹号有什么区别?
鉴于这样的一段代码:swift中的问号和感叹号有什么区别?
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,但是当我使用?我没有收到错误,但我正在尝试加载的屏幕不会加载,直到刷新?
想法?
dispatch_async(dispatch_get_main_queue()){\更新UI代码}
这是对问题的回答或尝试编辑吗?请解释此代码的作用或编辑问题。 – JJJ
@JJJ:看起来像他们复制[此评论](https://*.com/questions/38650152/what-is-the-difference-between-question-mark-and-exclamation-point-in-swift/38650353 #comment64682762_38650152),他们回复了*真棒作品很好,谢谢*。大概这是某种答案。 –
作为你需要让主队列更新UI –
异步方法http://*.com/questions/24122601/swift-variable -decorations-with-question-mark-and-exclamation-mark?rq = 1 – Shad
@LeoDabus你可以多做一点,以及如何做到这一点? –