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
  • 314,917
  • 42
  • 532
  • 579
tccpg288
  • 3,242
  • 5
  • 35
  • 80

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
  • 4,238
  • 1
  • 20
  • 33