Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post promise error #45

Closed
AlbanPerli opened this issue Aug 7, 2017 · 6 comments
Closed

Post promise error #45

AlbanPerli opened this issue Aug 7, 2017 · 6 comments

Comments

@AlbanPerli
Copy link

AlbanPerli commented Aug 7, 2017

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
Copy link
Member

s4cha commented Aug 7, 2017

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
Copy link
Author

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
Copy link
Author

@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
Copy link
Member

s4cha commented Aug 8, 2017

@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鈥檇 be interested to support it too. Maybe we could colalborate on it?

Cheers,

@AlbanPerli
Copy link
Author

Sure @s4cha 馃憤 At the end of august.

@AkdM
Copy link

AkdM commented Dec 28, 2017

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants