Coder Social home page Coder Social logo

repeating characters... about swifthttp HOT 11 CLOSED

daltoniam avatar daltoniam commented on July 24, 2024
repeating characters...

from swifthttp.

Comments (11)

daltoniam avatar daltoniam commented on July 24, 2024

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

from swifthttp.

acmacalister avatar acmacalister commented on July 24, 2024

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

from swifthttp.

daltoniam avatar daltoniam commented on July 24, 2024

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.

from swifthttp.

rblalock avatar rblalock commented on July 24, 2024

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);
        });

from swifthttp.

daltoniam avatar daltoniam commented on July 24, 2024

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)
})

from swifthttp.

rblalock avatar rblalock commented on July 24, 2024

Oh snap. It is!

starting a request
starting a request
ssuucccceessss!!

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

from swifthttp.

rblalock avatar rblalock commented on July 24, 2024

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.

from swifthttp.

rblalock avatar rblalock commented on July 24, 2024

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.

from swifthttp.

daltoniam avatar daltoniam commented on July 24, 2024

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)
})

from swifthttp.

rblalock avatar rblalock commented on July 24, 2024

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.

from swifthttp.

daltoniam avatar daltoniam commented on July 24, 2024

Sweet, thanks for the feedback!

from swifthttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.