title: Swift 2 if let with do-try-catch
body: <p>In Swift 1.2 I have this:</p>
  
  <pre><code>if let filePath = NSBundle.mainBundle().pathForResource("some", ofType: "txt"),
         data = String(contentsOfFile: filePath, encoding: NSUTF8StringEncoding) {
      for line in data.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) {
          // Do something
      }      
  } else {
      println("some.txt is missing")
  }
  </code></pre>
  
  <p>In Swift 2, I can no longer do this, because both <code>pathForResource</code> and <code>contentsOfFile</code> can throw, as well as returning optionals. I can fix it, but it now seems remarkably verbose:</p>
  
  <pre><code>do {
      if let filePath = try NSBundle.... {
          do {
              if let data = try String.... {
                  for line in data..... {
                      // Do something
                  }
              } else {
                  print("Nil data")
              }
          } catch {
              print("contentsOfFile threw")
          }
      } else {
          print("Nil pathForResource")
      }
  } catch {
      print("pathForResource threw")
  }      
  </code></pre>
  
  <p>I expect I have missed something - any help appreciated.</p>