Comments (11)
Are you using xCode 6 or 6.1? Can you share an example of the Swift code you used?
from swifthttp.
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.
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.
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.
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.
Oh snap. It is!
starting a request
starting a request
ssuucccceessss!!
{{""ssuucccceessss""::ttrruuee,,""iidd""::""bb4422ddb33e5200--44ff11cc--1111ee44--99881188--aa11997733ffbbaa88ffee33"",,""aaccccoouunnttss""::[[]]}}
from swifthttp.
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.
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.
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.
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.
Sweet, thanks for the feedback!
from swifthttp.
Related Issues (20)
- Count is unavailable: there is no universally good answer, see the documentation comment for discussion HOT 5
- HTTP.POST() not working after screen-lock (iOS 9.3.5)
- How to handler download progress?
- 'count' is unavailable: there is no universally good answer, see the documentation comment for discussion
- failed in xcode9.3
- Pinning Trusted certs or keys HOT 2
- POST method parameters lost in traffic
- Parameters not converted properly when using arrays HOT 2
- Cannot upload file
- Progress closure seems broken
- Post objects array to server
- Ambiguous use of 'init(urlString:parameters:headers:cachePolicy:timeoutInterval:)'
- Retry a task?
- Why OperationQueue support has been removed?
- SSL Pinning - Code=-999 "cancelled" HOT 1
- Linux support ?
- Timeout
- 'taskMap' Dictionary related crashes in Operation.swift file HOT 3
- Cannot consume as Swift package
- SSL Pinning - Always failing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swifthttp.