freshOS / ws-deprecated

āš ļø Deprecated - (in favour of Networking) :cloud: Elegantly connect to a JSON api. (Alamofire + Promises + JSON Parsing)
MIT License
353 stars 32 forks source link

Post promise error #45

Closed AlbanPerli closed 7 years ago

AlbanPerli commented 7 years ago

Hi, first, thanks for your good job! (especially with Stevia šŸ‘ )

I wanted to use your lib (v2.0.4) to post some datas but...

When I try this:

import Arrow
import then
import ws

let ws = WS("")
ws.post("", params: ["":""]).then { json in }

Produce error: Ambiguous use of 'post(_:params:)'

And when used like in the get example:

func test() -> Promise<JSON> {
        return ws.post("", params: ["":""])
}

Produce error: No 'post' candidates produce the expected contextual result type 'Promise'

Any ideas? Did I miss something?

Tell me if I can help!

Merci :)

s4cha commented 7 years ago

Hello @AlbanPerli,

Concerning the "ambiguous" parameter. This is because post is generic, which has lots of advantages, like keeping the api small, but the drawback is needing to give it the type :)

This yields an error :

ws.post("", params: ["":""]).then { json in }

while the following doesn't :

ws.post("", params: ["":""]).then { (json:JSON) in { }

The way it's usually meant to be used is "wrapped" in a function that gives the type.

func postSomething() -> Promise<JSON> {
  return ws.post("", params: ["":""])
}

// later
postSomething().then { json in 
}

As for the second error, this compiles fine on my end :/ I am trying to reproduce it with no luck,

Hope it helps :)

De rien!

AlbanPerli commented 7 years ago

Thanks for the quick response! The generic part is what I'm looking for :D

I've read the issue #11 And tried it, but I've now this error: Cannot invoke 'then' with an argument list of type '((JSON) -> () -> ())'

And of course, still the same error for the test() method...

It comes from cocoapods, pod 'ws', '~> 2.0' and it's build with the latest xCode.

I don't understand why the get() method is working, it seems to be build the same way, right?

AlbanPerli commented 7 years ago

@s4cha ...Found!

the Arrow framework has a JSON Class. I'm using SwiftyJSON, with a Class named JSON too.

It leads to strange behaviours, with poor error description. Without this class, everything's work as expected with ws

It could be interesting to make ws compatible with SwiftyJSON Used with SwiftyJSONAccelerator it could be even faster to get swift model from json API.

I'll look about it.

Thank!

s4cha commented 7 years ago

@AlbanPerli glad you found it! Have you tried specifying Arrow.JSON to remove the type ambiguity? WS is meant to work with Arrow out of the box but Swiftjson being the goto json parser for a lot of ios devs Iā€™d be interested to support it too. Maybe we could colalborate on it?

Cheers,

AlbanPerli commented 7 years ago

Sure @s4cha šŸ‘ At the end of august.

AkdM commented 6 years ago

Any update on this?