1

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.

agf119105
  • 1,770
  • 4
  • 15
  • 22
  • 2
    possible duplicate of [How to use Core Data Integer 64 with Swift Int64?](http://stackoverflow.com/questions/24350686/how-to-use-core-data-integer-64-with-swift-int64) - In short: Use NSNumber. The scalar accessor methods of Core Data do currently not work with Swift. – Martin R Jul 03 '14 at 14:53

1 Answers1

1

Try this

newItem.custjobcost = textfield.text.bridgeToObjectiveC().doubleValue
Marius Fanu
  • 6,589
  • 1
  • 17
  • 19
  • Why should that help? – Martin R Jul 03 '14 at 15:13
  • It helps because `bridgeToObjectiveC()` gets the `NSString` version of the `String`, and that has a valid `doubleValue` method. Same thing works for all the other scalar accessors of Strings, like `length` and the other `*Value`s. – NRitH Jul 03 '14 at 15:19
  • Thanks for the attempt, but I tried this already and the same error - it won't let me past it! – agf119105 Jul 03 '14 at 16:41
  • 1
    `textField.text.bridgeToObjectiveC().doubleValue` does the same as `(textfield.text as NSString).doubleValue` which is used in the question. – Martin R Jul 03 '14 at 17:34