0

I have an array of URL's I am trying to load into an ImageView using KingFisher.

arrPageTitle = ["This is The App Guruz", "This is Table Tennis 3D", "This is Hide Secrets"];
    arrPagePhoto = ["https://s3.amazonaws.com/fan-polls/heyward_again.jpg", "https://s3.amazonaws.com/fan-polls/Schwarber.jpg", "https://s3.amazonaws.com/fan-polls/mike_ditka.jpg"];

I am trying to load the appropriate image based on the index of the UIPageViewController:

pageContentViewController.imageView.kf_setImageWithURL((arrPagePhoto[index] as! String))

I am receiving `fatal error: unexpectedly found nil while unwrapping an Optional value

Any help is appreciated!

rmaddy
  • 307,833
  • 40
  • 508
  • 550
tccpg288
  • 3,004
  • 5
  • 31
  • 74

1 Answers1

2

As I know, kf_setImageWithURL require NSURL, not String.

So convert arrPagePhoto[index] to NSURL first then pass it to kf_setImageWithURL:

let downloadURL: NSURL = NSURL(string: arrPagePhoto[index])!

pageContentViewController.imageView.kf_setImageWithURL(downloadURL)
ilovecomputer
  • 3,720
  • 19
  • 33