title: Checking for nil parameter and if that parameter is an empty string in Swift
body: <p>There may or may not be an easier way to write this, but I feel like being a novice at Swift, I am probably missing something. I have a parameter (fileName) for a method that is an optional <code>String?</code> I need to check if it is <code>nil</code>, or if it is an empty String. This is the code I have, and it works fine, but it seems like it could be a bit more concise/readable.</p>
  
  <pre><code>func writeFile(fileName: String?, withContents contents: String, errorCallback failureCallback: RCTResponseSenderBlock, callback successCallback: RCTResponseSenderBlock) -&gt; Void {
  
    // If fileName has a value -- is not nil
    if let fileName = fileName {
      // Check to see if the string isn't empty
      if count(fileName) &lt; 1 {
        // Craft a failure message
        let resultsDict = [
          "success": false,
          "errMsg": "Filename is empty"
        ]
  
        // Execute the JavaScript failure callback handler
        failureCallback([resultsDict])
  
        return; // Halt execution of this function
      }
      // else, fileName is nil, and should return the same error message.
    } else {
      // Craft a failure message
      let resultsDict = [
        "success": false,
        "errMsg": "Filename is empty"
      ]
  
      // Execute the JavaScript failure callback handler
      failureCallback([resultsDict])
  
      return; // Halt execution of this function
    }
  }
  </code></pre>