In the code below, I have removed all other processing in the block. I am getting an error "fatal error: unexpectedly found nil while unwrapping an Optional value." The error occurs on the line
let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)!
I have determined that the problem is that there is a section symbol in the page. A hex dump of data
shows an A7 (so It's not an html tag). If I remove the symbol from the page, the problem goes away. (Unfortunately, I don't have control of the 'live' pages)
How do I keep this error from happening?
let attemptedURL = NSURL(string: "http://www.ilnb.uscourts.gov/sites/all/ajax/calendar.php?mobile=true&judge=\(hearJudge)&start=\(hearDate)&print=true")
print(attemptedURL)
if let url = attemptedURL {
// Create a task to run the web content through
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if let urlContent = data {
var contThis = true
let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)!
Thank you in advance.