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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repeating characters... #22

Closed
rblalock opened this issue Oct 8, 2014 · 11 comments
Closed

repeating characters... #22

rblalock opened this issue Oct 8, 2014 · 11 comments

Comments

@rblalock
Copy link

rblalock commented Oct 8, 2014

Just pulled this down to test it out. Looks great.

Pinged a local REST api and get the following

{{""ssuucccceesss"s:"t:rtureu,e",i"di"d:"":8"78a78ab8466604-04-f41f71-71-11e14e-49-891881-8a-1a917937f3bfab8af8ef3e"3,"",a"caccocuonutnst"s:"[:][}]

This is true with anything - errors, responses, etc. Repeats letters multiple times.

@daltoniam
Copy link
Owner

Are you using xCode 6 or 6.1? Can you share an example of the Swift code you used?

@acmacalister
Copy link
Collaborator

I tried this out in Xcode 6.1 with my Github Swift project that is using SwfitHTTP against the Github API I was able to decode the JSON without any repeating characters.

https://github.com/acmacalister/Github-Swift

@daltoniam
Copy link
Owner

Also, do you have multiple requests going at once? If you call println() from multiple threads/requests, then you could possibly get mixed characters in the debugger output, but the values in the actual data object should be fine.

@rblalock
Copy link
Author

rblalock commented Oct 8, 2014

Maybe its because I'm out of date. I'm using Xcode Version 6.0.1 (6A317)

Code is as simple as

        httpRequest.GET(path, parameters: nil, success: {(response: HTTPResponse) in
            if response.responseObject != nil {
                let data = response.responseObject as NSData
                let str = NSString(data: data, encoding: NSUTF8StringEncoding)
                println(str);
            }

        }, failure: {(error: NSError) in
            println(error);
        });

@daltoniam
Copy link
Owner

I think that Xcode version should be ok, it is the version I am running. To narrow it down, can you try this for me:

println("starting a request") //check to see if the request is run twice...
httpRequest.GET(path, parameters: nil, success: {(response: HTTPResponse) in
    println("success!")
    if response.responseObject != nil {
        let data = response.responseObject as NSData
        let str = NSString(data: data, encoding: NSUTF8StringEncoding)
        println(str)
    }

}, failure: {(error: NSError) in
    println(error)
})

@rblalock
Copy link
Author

rblalock commented Oct 8, 2014

Oh snap. It is!

starting a request
starting a request
ssuucccceessss!!

{{""ssuucccceessss""::ttrruuee,,""iidd""::""bb4422ddb33e5200--44ff11cc--1111ee44--99881188--aa11997733ffbbaa88ffee33"",,""aaccccoouunnttss""::[[]]}}

@rblalock
Copy link
Author

rblalock commented Oct 8, 2014

wait. duh. Sorry. That's because I am calling this twice in my call for two separate requests. They are two separate instances though. When I was using NSURLSession - the two request instances worked.

@rblalock
Copy link
Author

rblalock commented Oct 8, 2014

Yeh so what I'm seeing is I'm entering in to the method that calls this http lib twice...but it only ever makes once request.

@daltoniam
Copy link
Owner

yeah that makes sense. The println() aren't "thread safe" so they are running into each other. Your response data should be fine, but just to show:

println("starting a request") //check to see if the request is run twice...
httpRequest.GET(path, parameters: nil, success: {(response: HTTPResponse) in
    dispatch_async(dispatch_get_main_queue(),{ //putting it on the main thread to make the logging look nice
      println("success!")
      if response.responseObject != nil {
        let data = response.responseObject as NSData
        let str = NSString(data: data, encoding: NSUTF8StringEncoding)
        println(str)
      }
    })

}, failure: {(error: NSError) in
    println(error)
})

@rblalock
Copy link
Author

rblalock commented Oct 8, 2014

Ah I see. I guess from a dev user UX, I would've expected the success callback to behave the same as NSURLSession dataTaskWithRequest's callback (or similar method).

Thanks! This lib looks great.

@daltoniam
Copy link
Owner

Sweet, thanks for the feedback!

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