0

I am trying to add my textfield into the coredata as an float value, when user press a submit button. I have an error

Thread 1:EXC_BAD_ACCESS(code=1,address=0x1)

My attributes inside .xcdatamodel file and NSManagedObject class are set to type float.

 @IBOutlet weak var forceEntered: UITextField!
 @IBOutlet weak var stiffnessEntered: UITextField!


 @IBAction func submit(sender: AnyObject) {

        let appDel : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        let contxt : NSManagedObjectContext = appDel.managedObjectContext!
        let en = NSEntityDescription.entityForName("SpringVariables", inManagedObjectContext: contxt)
        var newItem = SpringModel(entity:en!,insertIntoManagedObjectContext: contxt)

        newItem.stiffness = (stiffnessEntered.text as NSString).floatValue //error message shows here.
        newItem.force = (forceEntered.text as NSString).floatValue


 }
Cherry_thia
  • 696
  • 1
  • 10
  • 24

0 Answers0