简体   繁体   中英

How do I check if UIImage is empty in swift?

This is my code but it seems the conditional "if" check for UIImage being empty is not executing. Is it the wrong way of checking if UIImage is empty? I have also tried

if allStyleArrays[i][ii][iii] as UIImage? == nil {
  ...
}

And not working, please if none of those methods checks, what is the correct way?

Thanks.

Code:

for var i = 0; i <= allStyleArrays.count; i++ {

                if i == allStyleArrays.count {
                self.performSegueWithIdentifier("toStylistReviewAndConfirm", sender: self)

            } else {

            for var ii = 0; ii < allStyleArrays[i].count; ii++ {

                for var iii = 0; iii < allStyleArrays[i][ii].count; iii++ {

                    if allStyleArrays[i][ii][iii] as UIImage? == UIImage(named: "") {

                    } else {

                        switch i {
                        case 0:
                            styleN[0].append(allStyleArrays[i][ii][iii])
                            //print("style 1 \(style1.count)")
                            break

                        case 1:
                            styleN[1].append(allStyleArrays[i][ii][iii])
                            //print("style 2 \(style2.count)")
                            break

                        default:
                            styleN[2].append(allStyleArrays[i][ii][iii])
                            //print("style 3 \(style3.count)")
                            break
                        }

                    }

                }

            }

        }

    }

尝试

if allStyleArrays[i][ii][iii].imageAsset == 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