user2164327
user2164327

Reputation: 283

swift array uiimage animation

I'm trying to animate a UIImage and I have an UIImageView called MainPic.

This is the code I am using:

     @IBOutlet weak var MainPic: UIImageView!> 

        MainPic.animationImages = [
         UIImage(named: "fox01")!,
         UIImage(named: "fox02")!,
         UIImage(named: "fox03")!,
         UIImage(named: "fox04")!,
         UIImage(named: "fox06")!
        ]

     MainPic.animationDuration = 1
     MainPic.startAnimating()

I made sure all the images were in the project. I've tried including them using the .jpg extension.

However, I am getting this error:

fatal error: unexpectedly found nil while unwrapping an Optional value

What is wrong with my code?

Upvotes: 2

Views: 2049

Answers (1)

hsafarya
hsafarya

Reputation: 1053

There is ha two cases:

  1. MainPic is nil
  2. One of the UIImage(named: "fox01") is nil

You can easily catch which item is nil, by simply printing all items before using. I can help more if you share more code or upload a simple example which reproducing your case.

Upvotes: 1

Related Questions