I am new to programming and swift with a little experience in Java and would really appreciate it if you guys could help me with a problem I am having. Currently I am trying to save an array when the app is closed and print it to the log after the app is loaded again but anytime I close it I get the error
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
Here is the part of the code where I try to save it. It is in the appdelegate file which is where I assume is a correct place to put it.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let data = NSUserDefaults.standardUserDefaults()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}
var savedAssignments = ""
func applicationWillResignActive(application: UIApplication) {
data.setValue(Assignments, forKey: "savedAssignments")
}
func applicationDidEnterBackground(application: UIApplication) {
data.setValue(Assignments, forKey: "savedAssignments")
}
func applicationWillEnterForeground(application: UIApplication) {
}
func applicationDidBecomeActive(application: UIApplication) {
print(data)
print(savedAssignments)
print(Assignments)
}
func applicationWillTerminate(application: UIApplication) {
}
}