قالب وردپرس درنا توس
Home / IOS Development / I need help with my PromiseKit code: iOSProgramming

I need help with my PromiseKit code: iOSProgramming



I'm trying to chain Promise methods, but I'm getting wrong. I try to write a single method, "addZipCode", which returns a promise, which first hits the network to retrieve any weather data, and then calls another method that stores the weather data into a data directory. I have these two methods, both back Promises …

      public func addZipCode (zipCode: ZipCode) -> Promise <[ZipCode:Temperature]> {
return first {
self.weatherAPI.getCurrentTemperature (forZipCode: zipCode)

// This line causes a compiler error that says "Cannot convert the value of the type
// & # 39; (Temperature) -> Promise <[ZipCode : Temperature]>? & # 39; (aka & (39) (Int) ->
// Optional <Promise <Dictionary  >> & # 39;) to expected argument type
// & # 39; (Temperature) -> _ & # 39; (aka & # 39; (Int) -> _ & # 39;) "
} the temperature in
self? .dataStore.saveZipCode (zipCode: zipCode, temperature: temperature)
}
}

public func getCurrentTemperature (forZipCode zipCode: ZipCode) -> Promise  {
return Promise () {[weak self] seal in
self? .openWeather.currentWeather (forZipCode: zipCode, callback: {(item, error) in
if la temp = element? .main.fahrenheit.currentTemp {
seal.fulfill (int (temp))
return
}
seal.fulfill (0)
})
}
}

public func saveZipCode (zipCode: ZipCode,
temperature: temperature) -> lift <[ZipCode:Temperature]> {
return Promise {seal in
self.readZipCodes (). entered {[weak self] zipCodes
guard let myself = even else {return}
var zips = zipCodes
zipper [zipCode] = temperature
leave encoder = JSONEncoder ()
let jsonData = try! encoder.encode (zippers)

guard let docsURL = self.docsURL other {
seal.reject (MyError.any)
return
}
try? jsonData.write (to: docsURL.appendingPathComponent (self.jsonFilename))
seal.fulfill (zippers)
} .Cauterize ()
}
}

What am I doing wrong? Thanks!


Source link