numaralı argümanlara yönelik argümanlar gerektirir. Reference to generic type Dictionary requires arguments in <...>
hatası, işlevin ilk satırında görüntülenir. Fonksiyonun bir api'den alınan bir NSDictionary döndürmesini sağlamaya çalışıyorum. Burada neler olabileceğini bilen var mı?Hızlı hata: Genel türden sözlüğe başvuru, <...>
class func getCurrentWeather(longitude: Float, latitude: Float)->Dictionary?{
let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apikey)/")
let forecastURL = NSURL(string: "\(longitude),\(latitude)", relativeToURL:baseURL)
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
if(error == nil) {
println(location)
let dataObject = NSData(contentsOfURL:location!)
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
return weatherDictionary
}else{
println("error!")
return nil
}
})
}
DÜZENLEME:
İkinci Sayı:
class func getCurrentWeather(longitude: Float, latitude: Float)->NSDictionary?{
let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apikey)/")
let forecastURL = NSURL(string: "\(longitude),\(latitude)", relativeToURL:baseURL)
let sharedSession = NSURLSession.sharedSession()
let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in
if(error == nil) {
println(location)
let dataObject = NSData(contentsOfURL:location!)
let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject!, options: nil, error: nil) as NSDictionary
return weatherDictionary //ERROR: NSDictionary not convertible to void
}else{
println("error!")
return nil ERROR: Type void does not conform to protocol 'NilLiteralConvertible'
}
})
}
teşekkür! İlk hatayı çözdü ancak şimdi 'NSDictionary' 'Void' 'e dönüştürülemeyen bir mesaj alıyorum. Sizce burada ne oldu? –
@ user1851782: Hatayı nereden aldınız? Ve şimdi hangi kodu kullanıyorsunuz? –
@ user1851782: Bunun nedeni, downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL (tahminURL !, completionHandler: {: location: NSURL !, yanıt: NSURLResponse !, hata: NSError!) -> Void in 'tir zaman uyumsuz bir çağrı –