I have a custom image class and I am just trying to check if its not nil.
Every syntax I try (with the above being my best guess) keeps saying my iImage is not a UInt8.
First: why is it thinking by comparing to nil its a UInt8 in the first place?
Second: how can I check if my custom class is nil?
Update:
Answers are appreciated but didn't work. Here is full code block
private class func doubleLayoutView(mainView:UIView,images:Array<iImage>)
{
for i in 0...1{
var image:iImage = images[i]
if image.uiImage!=nil
{
image.imageFrame = CGRectMake(CGFloat(i)*mainView.frame.width/2, 0, mainView.frame.width/2, mainView.frame.height)
}
}
}
I have a custom image class and I am just trying to check if its not nil
Be sure that iamge.uiImage
is Optional. Otherwise you can't compare it to nil
In this case Swift helps you do avoid extra validation != nil
.
On other hand if uiImage
is not Optional (a.e. marked without ?
) means that this value is not nil
and you can remove if
validation statement because it doesn't make sense
how can I check if my custom class is nil?
If you feel pretty confident that custom class is not nil
- don't check it. If it might be nil
- define it as Optional like:
var uiImage:UIImage?
In this case each time when you are going to use it, need to unwrap it 1st
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments