Checking if an NSUserDefaults key exists or not crashes the app
<p>The following code is in my <strong>AppDelegate</strong> <code>didFinishLaunchingWithOptions launchOptions:</code> method. When I try to  run the app, it crashes.</p>

<pre><code>var accessToken = ""
if let key = NSUserDefaults.standardUserDefaults().objectForKey("accesstoken"){
         accessToken = key as! String
        }
</code></pre>

<p>The only crash log I get from Xcode is: </p>

<p><a href="https://i.stack.imgur.com/yhUSP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yhUSP.png" alt="enter image description here"></a></p>

<p>I also have tried :</p>

<pre><code>if  NSUserDefaults.standardUserDefaults().objectForKey("accesstoken") != nil {
}
</code></pre>

<p>Can anyone help me to solve the issue ?</p>