Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x70 error when appDelegate when clicking "Save" or "back"

I get the following thread 1: EXC_BAD_ACCESS (code=1, address = 0x70 error message thread 1: EXC_BAD_ACCESS (code=1, address = 0x70 when I am in my addCustomerViewController , and either save the click that at the end of the code launches self.navigationController!.popViewControllerAnimated(true) , or when I click back in the same addCustomerViewController . The line of code highlighted with an error is in my AppDelegate class, and the first line looks like this

 class AppDelegate: UIResponder, UIApplicationDelegate{ 

This is the last message I receive in the debug area. Not sure if this is related.

 2015-06-17 23:03:03.744 SalesCRM[4930:1409291] CoreData: error: Failed to call designated initializer on NSManagedObject class 'Customer' 

Here is the save function. Let me know what other code you might need. I lost how to fix it.

 @IBAction func save(sender: AnyObject) { let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let context:NSManagedObjectContext = appDel.managedObjectContext if firstName.text != "" && lastName.text != "" && phoneNumber.text != "" { let newUser = NSEntityDescription.insertNewObjectForEntityForName("Customer", inManagedObjectContext: context) as NSManagedObject newUser.setValue(firstName.text?.lowercaseString, forKey: "firstName") newUser.setValue(lastName.text?.lowercaseString, forKey: "lastName") newUser.setValue(phoneNumber.text, forKey: "phoneNumber") newUser.setValue(email.text, forKey: "email") newUser.setValue(notes.text, forKey: "notes") var name = String() name = lastName.text! print(name) var index = advance(name.startIndex, 0) print(index) first = String(name[index]).lowercaseString newUser.setValue(first, forKey: "first") let todaysDate:NSDate = NSDate() let dateFormatter:NSDateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM-dd-yyyy hh:mm" let DateInFormat:String = dateFormatter.stringFromDate(todaysDate) + ": created" newUser.setValue(DateInFormat, forKey: "log") try! context.save() let request = NSFetchRequest(entityName: "Customer") let results = try! context.executeFetchRequest(request) print(results) } else { let alert = UIAlertController(title: "Error", message: "Please enter all information", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alert, animated: true, completion: nil) } self.navigationController!.popViewControllerAnimated(true) } 
+5
source share

All Articles