title: How to use (?) and (!) in Swift
body: <p>I'm new to swift and I'm having some difficulties understanding on how to use (!) and (?)</p>
  
  <p>As far as I know, we can use (?) when there are instances that a variable can be nil.
  And use (!) when you are 100% sure that item is not nil.</p>
  
  <p><strong>1. Working Fine - Optionals</strong></p>
  
  <pre><code>var john:String?
  john = "Is my name"
  println(john!)
  </code></pre>
  
  <p><strong>2. Crashes on Runtime - ! must not be nil - means this is correct</strong> </p>
  
  <pre><code>var john:String?
  println(john!)
  </code></pre>
  
  <p><strong>3. Works Fine</strong></p>
  
  <pre><code>var dict: [String:AnyObject] = Dictionary()
  dict["name"] = "John"
  var str: String = dict["name"]! as String &lt;--- Taking away the (!) says it's not convertible to String
  </code></pre>
  
  <p><strong>4. Cannot Run/Build - for me it's similar to 1.</strong></p>
  
  <pre><code>var dict: [String:AnyObject]? = Dictionary() ---error says does not have a member named 'subscript'
  dict["name"] = "John"
  var str: String = dict["name"]! as String
  </code></pre>
  
  <p><strong>5. Unexpectedly found nil while unwrapping an optional value</strong></p>
  
  <pre><code>var dict: [String:AnyObject] = Dictionary()
  dict["name"]? = "John"
  var str: String = dict["name"]! as String
  </code></pre>
  
  <p>Would be great if someone can help me understand these things. Thanks!</p>