[GH-ISSUE #131] Please tell me I'm totally missing something… #80

Closed
opened 2026-03-03 16:45:30 +03:00 by kerem · 3 comments
Owner

Originally created by @ts on GitHub (Oct 21, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/131

New to Swift, and for all intents and purposes, iOS and Cocoa in general. That said, what is going on in OAuthSwifttClient.get that I don't seem to understand? It returns NSData and I can't for the life of me parse anything useful out of it.

My simple test is as follows:

        oauthswift.client.get("https://www.strava.com/api/v3/athlete/activities", parameters: ["per_page":10], success: {
            data, response in

                do {
                    print(data)
                    if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? NSDictionary {
                        print("jsonResult: \(jsonResult)")
                    }
                } catch {
                    print("error: \(error)")
                }
            }, failure: {
                error in
                    print("error: \(error)")
        })

To which I get the raw NSData as expected, but without anything following.

I'm sure I just don't understand Swift/Cocoa/Xcode or something because this is extremely simple stuff and there is no way it should be this difficult to work with.

Originally created by @ts on GitHub (Oct 21, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/131 New to Swift, and for all intents and purposes, iOS and Cocoa in general. That said, what is going on in `OAuthSwifttClient.get` that I don't seem to understand? It returns `NSData` and I can't for the life of me parse anything useful out of it. My simple test is as follows: ``` oauthswift.client.get("https://www.strava.com/api/v3/athlete/activities", parameters: ["per_page":10], success: { data, response in do { print(data) if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? NSDictionary { print("jsonResult: \(jsonResult)") } } catch { print("error: \(error)") } }, failure: { error in print("error: \(error)") }) ``` To which I get the raw `NSData` as expected, but without anything following. I'm sure I just don't understand Swift/Cocoa/Xcode or something because this is extremely simple stuff and there is no way it should be this difficult to work with.
kerem closed this issue 2026-03-03 16:45:30 +03:00
Author
Owner

@phimage commented on GitHub (Oct 21, 2015):

Just to debug try convert the NSData to String or NString

You cast as NSDico.. add an else {...} or remove the cast

<!-- gh-comment-id:150028324 --> @phimage commented on GitHub (Oct 21, 2015): Just to debug try convert the NSData to String or NString You cast as NSDico.. add an else {...} or remove the cast
Author
Owner

@ts commented on GitHub (Oct 21, 2015):

Sounds like the right thing to do, but again, I'm kneecapped by Swift and the new territory I've found myself in. When I print(String(data)) I get exactly the same result as before (raw NSData), which isn't human-readable or yet usable (hence trying to use NSJSONSerialization it in the first place…) so I'm not sure what to do now.

<!-- gh-comment-id:150031137 --> @ts commented on GitHub (Oct 21, 2015): Sounds like the right thing to do, but again, I'm kneecapped by Swift and the new territory I've found myself in. When I `print(String(data))` I get exactly the same result as before (raw NSData), which isn't human-readable or yet usable (hence trying to use `NSJSONSerialization` it in the first place…) so I'm not sure what to do now.
Author
Owner

@phimage commented on GitHub (Oct 22, 2015):

Look for NSData to NString, encoding must ne specified in init
let datastring = NSString(data: myData, encoding:NSUTF8StringEncoding)

<!-- gh-comment-id:150090727 --> @phimage commented on GitHub (Oct 22, 2015): Look for NSData to NString, encoding must ne specified in init `let datastring = NSString(data: myData, encoding:NSUTF8StringEncoding)`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#80
No description provided.