Mxyb
Mxyb

Reputation: 415

Kingfisher not loading images in SwiftUI

I am trying to implement Kingfisher to handle my images because I am doing them manually at the moment and it's not good. I seem to be having some issues though.

I downloaded this pod via CocoaPods:

pod 'Kingfisher', '~> 7.0'

And I changed this code:

import Kingfisher

if let dataDecoded: NSData = NSData(base64Encoded: businessData.business_logo ?? "", options: NSData.Base64DecodingOptions(rawValue: 0)) {
        if let decodedimage: UIImage = UIImage(data: dataDecoded as Data) {
            Image(uiImage: decodedimage)
               .resizable()
        }
}

To this code:

import Kingfisher

if let url = URL(string: businessData.business_logo ?? "") {
    KFImage(url)
      .resizable()
}

When I run the code, this is printed to the console:

2023-05-08 17:58:33.751513+0100 Project Name[23531:243997] Task <1F4ADD8F-C550-460C-87B3-307E9BDFFD20>.<1> finished with error [-1002] Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL,

Any ideas on why this is happening? Is there a SwiftUI version of the pod I need?

Upvotes: 0

Views: 482

Answers (1)

Okan T.
Okan T.

Reputation: 76

I am using 7.11.0 version and there is a modifier which .onFailure tells to you what happen while load image. I suggest to you use this modifier like below and understand what happened correctly.

if let url = URL(string: stringUrl) {
KFImage(url)
    .resizable()
    .onFailure{ error in <-- like here
        print("error:" , error.localizedDescription)
    }
    .onSuccess{ result in
        print("success url: ", stringUrl)
    }}

Upvotes: 0

Related Questions