0

I'm working with some XML parsing...

I'm thinking of which errors I should be careful about:

  1. no Internet connection
  2. no data in the XML stream

What else?

How can I check for Internet connection errors? The only "link" to Internet is when the parser start the parse method

let url = NSURL(string: testUrl)
var parser = NSXMLParser(contentsOfURL: url)
parser.delegate = self
parser.shouldProcessNamespaces = true
parser.shouldResolveExternalEntities = true
parser.parse()

So how should I check?

Volker E.
  • 5,911
  • 11
  • 47
  • 64
giancula
  • 1
  • 1

1 Answers1

0

In terms of basic internet connectivity, you can use Reachability to identify when the device has connection to the Internet. You can trigger the initiation of the request once you've established that your server is reachable. If you want to see a video on how to use Reachability in Swift, this YouTube video seems like it might walk you through it.

The other errors fall under the broader category that valid XML was not returned. (Maybe that's what you meant by "no data in the XML stream".) Anyway, this could be for a myriad of different reasons, but they'd all be caught by parseErrorOccurred. (Actually, this probably catches the connectivity issue, too, but it's just that the action you want to take is probably better tackled with the Reachability approach.)

Rob
  • 415,655
  • 72
  • 787
  • 1,044