Skip to content

Instantly share code, notes, and snippets.

@keith
Last active October 11, 2016 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keith/a121589b4f376b46da868c70f7460ab3 to your computer and use it in GitHub Desktop.
Save keith/a121589b4f376b46da868c70f7460ab3 to your computer and use it in GitHub Desktop.
Implicitly unwrapped optional crash
import Foundation
func set<T>(value: T, forKey key: String) {
UserDefaults.standard.set(value, forKey: key) // this crashes because it's trying to store Optional<Date>
}
let date: Date! = Date()
set(value: date, forKey: "key")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment