title: How do I fix fatal error: Can't form a Character from an empty String
body: <p>I'm new to Swift and it took me 1h to debug, but I still don't know why it failed.</p>
  
  <p>This is a question from leetcode: to reverse a string:</p>
  
  <p>input: "hello"</p>
  
  <p>output: "olleh"</p>
  
  <p>And there is my code:</p>
  
  <pre><code>import Foundation
  class Solution {
      func reverseString(_ s: String) -&gt; String {
          // initialize a new null string
          var answer = ""
          // get the length of the input string
          var lengthOfString = s.characters.count
          // add the character into the new string
          for nums in 0...(lengthOfString-1){
              var index = s.index(s.startIndex, offsetBy: lengthOfString)
              answer.append(s[index])
              lengthOfString-=1
          }
          return answer
      }
  }
  
  let a = Solution()
  let b = a.reverseString("hello")
  print(b)
  </code></pre>
  
  <p>here is the picture of my error:</p>
  
  <p><a href="https://i.stack.imgur.com/q9a4A.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q9a4A.jpg" alt=""></a></p>