Swift: About assign nil to a var
<p>I was trying to learn about swift basics and I encountered this problem:</p>

<p>Assume we have a dic:</p>

<pre><code>var presidentialPetsDict = ["Barack Obama":"Bo", "Bill Clinton": "Socks", "George Bush": "Miss Beazley", "Ronald Reagan": "Lucky"]
</code></pre>

<p>And to Remove the entry for "George Bush" and replace it with an entry for "George W. Bush":</p>

<p>What I did:</p>

<pre><code>var oldvalue = presidentialPetsDict.removeValueForKey("George Bush")
if let value = oldvalue
{
    presidentialPetsDict["George W. Bush"] = value
}else
{
    print("no matching found")
}
</code></pre>

<p>Because I believe removeValueForKey method will return an optional value in case key "George Bush" will not return a value but nil so we need to safely unwrap it by using if let.
However, the solution code looks like this:</p>

<pre><code>var oldValue = presidentialPetsDict.removeValueForKey("Georgee Bush")
presidentialPetsDict["George W. Bush"] = oldValue
</code></pre>

<p>The part I don't understand is that if we want to assign nil to a var we usually do this:</p>

<pre><code>var value:String?
value = nil
</code></pre>

<p>But the solution code above works even though the method returns nil, could somebody explain why it worked because I think in solution we didn't declare oldValue as optional at all.</p>