aijayy
aijayy

Reputation: 25

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
                        }

                    }

                }

            }

        }

    }

Upvotes: 0

Views: 4800

Answers (1)

iDeveloper
iDeveloper

Reputation: 150

try

if allStyleArrays[i][ii][iii].imageAsset == nil

Upvotes: 2

Related Questions