Reputation: 1703
I have this function that make a request for the API:
Alamofire.request(URL).responseObject{ (response: DataResponse<Movie>) in
print("|MovieController| Response is: \(response)")
let movie = response.result.value
if let posterURL = movie?.posterURL {
print("Poster URL: \(posterURL)")
let imgStg: String = posterURL
print("-------> Image String: \(imgStg)")
}
}
I do print on my console the posterURL right, but the app crash when I try to let imgStg: String = posterURL.
First I was trying to do this:
let imgStg: String = movie!.posterURL!
let imgURL: URL? = URL(string: imgStg) //Error here: Cannot call value of non-function type 'String'
let imgSrc = ImageResource(downloadURL: imgURL!, cacheKey: imgStg)
But the xcode was showing this error. So I tried to see what am I getting in 'imgStg' and the app crash when executed this line. Why is that? How can I get this right?
PS.: my final goal is to cache the image using KingFisher like that:
posterImageView.kf.setImage(with: imgSrc)
Update 2: Trying typing from scratch and that's the options:
Upvotes: 0
Views: 564
Reputation: 4074
Error stating you that you are calling a String
instead of a method.
As I can see you are passing URL (not recommended to have same name) as parameter in request so its getting confused and throwing error. Try changing the name from URL to requestURL or something else.
Replace this:
Alamofire.request(URL).responseObject { (response: DataResponse<Movie>)
with:
Alamofire.request(requestURL).responseObject { (response: DataResponse<Movie>)
and definitely where you declared URL
change at that place too with requestURL
.
Upvotes: 1
Reputation: 19339
Your image actually shows a breakpoint (and not a runtime error as you imagined).
To disable it, just click on the line left margin. To disable all breakpoints use command + Y instead.
Breakpoints. A breakpoint is just a forced stop on a given source code line. As such, it isn't related to a specific buildtime or runtime error at all.
Upvotes: 1