当用户按下提交按钮时,我试图将我的文本字段添加到coredata中作为浮点值。我有一个错误
线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x1)
我在.xcdatamodel
文件和NSManagedObject
类中的属性设置为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
}