Ich habe ein Problem mit meinem Code. Ich versuche, ein Bild über eine StringBuilder
herunterzuladen und dann auf ein UIImage einzustellen Ich schein ein Problem zu bekommen und ich hoffe jemand kann sehen was ich falsch gemacht habe.Ambiguous Verweis auf Member 'Datatask (mit: Completionhandler :)'
setUI:
uiMovieTitle.text = self.movies![movieIndex].title
var finalImageUrl = StringBuilder()
let session = URLSession(configuration: .default)
let downloadPicTask = session.dataTask(with: finalImageUrl) { (data, response, error) in
// The download has finished.
if let e = error {
print("Error downloading cat picture: \(e)")
} else {
// No errors found.
// It would be weird if we didn't have a response, so check for that too.
if let res = response as? HTTPURLResponse {
print("Downloaded cat picture with response code \(res.statusCode)")
if let imageData = data {
// Finally convert that Data into an image and do what you wish with it.
let image = UIImage(data: imageData)
// Do something with your image.
uiMoviePoster.image = image
} else {
print("Couldn't get image: Image is nil")
}
} else {
print("Couldn't get response code for some reason")
}
}
}
downloadPicTask.resume()
}
String
func StringBuilder() -> (String){
let posterBase = "http://image.tmdb.org/t/p/w1920"
let linkEnd = self.movies?[movieIndex].posterPath
var finalLink = ""
finalLink = posterBase + linkEnd!
return finalLink
}
Ich habe auch einen anderen Download an, die mir eine Liste von Filmen (JSON) und ist entscheidend für die StringBuilder
bekommt.
StringBuilder sollte eine URL oder URLRequest zurückgeben –
Mögliches Duplikat von [Swift 3 URLSession.shared() Undeutlicher Verweis auf Member 'dataTask (mit: completionHandler :) error (bug)] (http://stackoverflow.com/questions/37812286/swift-3-urlsession-shared-zweideutig-Referenz-zu-Mitglied-Datataskwithcomplet) – shallowThought
Ich denke, Ihre 'finalLink' fehlt ein Schrägstrich'/'. Korrigiere es oder verwende besser "URL". – shallowThought