I´m new at programming and I get an error that I wasn´t able to solve yet, even the question didn´t help me: What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?
Here is the error:
fatal error: unexpectedly found nil while unwrapping an Optional value 2017-10-27 18:30:48.283483+0200 Inspireme1.0[1149:631849] fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
Here is my code:
var quotes: RandomItems! = RandomItems([
"Jonas",
"Mary",
"Michael",
"Jeff",
"Sarah",
])
@IBAction func PresentText(_ sender: Any) {
PresentingLabel.text = quotes.next() //<-- Error
}
var randomItems: RandomItems?
override func viewDidAppear(_ animated: Bool) {
// Code to load the struct again after the view appears.
let defaults = UserDefaults.standard
quotes = defaults.codable(RandomItems.self, forKey: "quotes")
}
override func viewWillDisappear(_ animated: Bool) {
// Code to save struct before the view disappears.
let defaults = UserDefaults.standard
if let quotes = quotes {
defaults.set(codable: quotes, forKey: "quotes")
}
}