Get readable info from NSErrorPointer

201 views Asked by At

Is there a way to get readable information from the following NSErrorPointer in Swift?

var downloadErrorPointer = NSErrorPointer();
self.rssString = String(contentsOfURL: url!, encoding: NSUTF8StringEncoding, error: downloadErrorPointer);
1

There are 1 answers

2
Sven On BEST ANSWER

You're not supposed to directly use an instance of NSErrorPointer. Instead you create an optional NSError variable and pass it's address using the & operator, just as in Objective-C:

var error : NSError? = nil
self.rssString = String(..., error: &error);

But with Swift 2 there is new syntax for error handling so this cannot be used any more. The new syntax is the following:

do {
   self.rssString = try String(...)
   // Everything OK, the rssString is valid
} catch let error as NSError {
   // This only gets executed if there was an error
}