简体   繁体   中英

How to unwrap optional value returns nil although it has value?

I have this piece of code where i am unwrapping an optional value, and in the debugger there is a value in this optional variable. But for some reason it is giving me null pointer exception !!!

码

调试器

在此处输入图片说明

Can any one explain why its finding nil although there is a value !!

It looks like self.fullresolutionimages, the array/dictionary, is the nil that is causing the error.

make sure that you allocate that first, self.fullResolutionImages = [UIImage]() ;

Also, I am not 100% sure if doing the index when there are no contents will work, so you may want to append instead, self.fullResolutionImages.append(self.fullResolutionImage) , or insert this way, self.fullResolutionImages.insert(self.fullResolutionImage, atIndex: 0)

fullResolutionImages = nil,消息正确,不是吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM