18

In Xcode 6.3 beta running Swift 1.2 I have seemingly successfully retrieved a JSON object from an API, but the debugger is claiming that the object has no properties. The API is running on localhost and is called like this:

  NSURLConnection.sendAsynchronousRequest( request, queue: queue,
    completionHandler: completionHandler )

completionHandler is a closure with a breakpoint in it:

let completionHandler =
{
  ( response: NSURLResponse!, data: NSData!, error: NSError! ) -> Void in
  // BREAKPOINT HERE
}

The debugger shows that in Xcode 6.3 beta with Swift 1.2 data: NSData! is an ObjectiveC.NSObject of 190 bytes but with no properties, which seems flatly contradictory. I simply want the JSON data that I hope is hidden somewhere in those bytes. I do not know whether the debugger, or code that needs updating for Swift 1.2, or my understanding of things, or something else is to blame. I simply want the JSON.

Post-script

The JSON data was there all along, as the byte count suggested, and getting it was very simple (using SwiftyJSON):

let json = JSON( data: data )

Quite what has happened to the properties in the Xcode 6.3 beta debugger remains a mystery though. I'm not adding this as an answer to my own question, because whilst it works it might not necessarily be the answer. I am too new to Swift to know what the actual answer might be, or even if there is one.

11
  • 5
    What's the actual problem? Which results are you expecting? Is the 6.3 version not working as intended? If so, can we remove all of the stuff about Xcode 6.2, and make this question more focused with a better explanation of what the problem actually is?
    – nhgrif
    Apr 4, 2015 at 16:51
  • Edited. It is possible to point out weaknesses without getting [passive-]aggressive nhgrif, we are all just trying to get along here. MJB. Apr 4, 2015 at 16:56
  • 4
    I'm not being passive-aggressive. I'm pointing out the concerns. Your question is unclear. I've voted to close it as such. Your question is about the Xcode 6.3 version, correct? So cut out all of the Xcode 6.2 stuff. It's only relevant so far as to say "This worked in 6.2, but now it does not work in 6.3". Then, clarify more your exact problem. Is the object simply being intrepreted incorrectly by the debugger (but you're still able to use it correctly)? Or are actually getting the wrong type of object returned from the method?
    – nhgrif
    Apr 4, 2015 at 16:59
  • I apologise for my lack of clarity. I feel that the 6.2 data is relevant because it shows what should be there, presumably is there given that both examples show a byte count of 190, but is somehow not there. Instead there is an NSObject with a value of (None), which is not useful. I presumed the image with (None) would describe the problem without me having to be ungraciously blunt about it. I was wrong, I apologise. I accept you weren't being passive-agressive, perhaps you could formulate your words in such a way as that does not become a possible interpretation in future? Apr 4, 2015 at 17:09
  • 3
    You can always delete your own question (as it has no answers with upvotes). Or, it might make sense to post a self-answer (but if you do, post some more of the necessary details in the question itself).
    – nhgrif
    Apr 4, 2015 at 20:18

1 Answer 1

2

NSData is an encapsulation of the raw data bytes, before it's translated into a string or parsed as JSON.

If you want to see what this data contains, then you can use NSJSONSerialization (let jsonDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil))

and then read the dictionary like any other: let value = jsonDictionary["key"]

I hope that's helpful.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.