I'm having trouble writing the following code:
public
func
get(organization inSID: String)
-> Promise<Organization>
{
URLSession.showNetworkActivity()
return firstly
{
let req = buildRequest(path: "/api/\(inUUID)", date: inDate, headers: [.organizationSID : inSID])
self.mgr.request(req).responseJSON()
}
.map()
{ inData, inResp in
return Organization(sid: "")
}
.ensure
{
URLSession.hideNetworkActivity()
}
}
I get an error on firstly
: Ambiguous reference to member 'firstly(execute:)'
After adding import PMKAlamofire
to the top of my file, and being more explicit, I get this to compile:
public
func
get(organization inSID: String)
-> Promise<Organization>
{
URLSession.showNetworkActivity()
return firstly
{ () -> Promise<(json: Any, response: PMKAlamofireDataResponse)> in
let req = buildRequest(path: "/api/v2/organizations/\(inSID)", headers: [.organizationSID : inSID])
return self.mgr.request(req).responseJSON()
}
.map()
{ inResp in
return Organization(sid: "")
}
.ensure
{
URLSession.hideNetworkActivity()
}
}
Note the added explicit () -> Promise<(json: Any, response: PMKAlamofireDataResponse)>
and the explicit return
statement in the firstly
closure. I don't know if this is now required by Swift 5 or it still can't properly infer types.