在 Xcode 6.1 中.'UIImage?'没有名为“size"的成员错误 [英] In Xcode 6.1. 'UIImage?' does not have a member named 'size' Error
问题描述
我正在获取图像的 Size
并使用以下代码.它在 Xcode 6.0.1
上运行得非常好.更新到 Xcode 6.1
后,我收到错误:
I'm getting an image's Size
and used the below code. It was working perfectly fine with Xcode 6.0.1
. After updating to Xcode 6.1
, I'm getting Error Like :
'UIImage?'没有名为 'size' 的成员
var image = UIImage(named: imageName)
let sizeOfImage = image.size
是我的代码还是 Apple 的错误?请帮我在这里.TIA.
Is it bug with my code or Apple ? Please help me in here. TIA.
推荐答案
该初始化器现在是一个可失败初始化器,因此它返回一个可选的 UIImage
.
That initializer is now a failable initializer, and as such it returns an optional UIImage
.
要快速修复您的错误,只需打开图片即可:
To quickly fix your bug just unwrap the image:
let sizeOfImage = image?.size
但我认为您将在代码中多次引用 image
变量,在这种情况下,我建议使用可选绑定:
but I presume you will reference the image
variable more than just once in your code, in that case I suggest using optional binding:
if let image = image {
let sizeOfImage = image.size
/// ...
/// Use the image
}
这篇关于在 Xcode 6.1 中.'UIImage?'没有名为“size"的成员错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!