How to save data to NSUserDefaults in Swift 3?
<p>I want to save my data into NSUSerDefaults in Swift3 in:</p>

<pre><code>func a() {
    let userDefaults = UserDefaults.standard
    let sessionData = NSKeyedArchiver.archivedData(withRootObject: session)
    userDefaults.set(session, forKey: "SpotifySession")
    userDefaults.synchronize()
}
</code></pre>

<p>but it crashes in</p>

<pre><code>NSKeyedArchiver.archivedData(withRootObject: session)
</code></pre>

<p>How can I fix that?</p>