agf119105
agf119105

Reputation: 1810

Why am I getting EXC_BAD_ACCESS error when converting to a float or a double? (In Swift)

I am trying to store some values from textfields as doubles and floats and I cannot get past the above error.

I have defined the property to match the attribute in my cordata database:

@NSManaged var custjobcost: Double

When I am mapping the properties in order to save them, I am using the following code, but it will not accept it - on runtime, I get the error indicated above.

newItem.custjobcost = (textfield.text as NSString).doubleValue

I have also the same thing, but with float and floatvalue instead.

Upvotes: 1

Views: 461

Answers (1)

Marius Fanu
Marius Fanu

Reputation: 6669

Try this

newItem.custjobcost = textfield.text.bridgeToObjectiveC().doubleValue

Upvotes: 1

Related Questions