infernouk infernouk - 1 year ago 76
Swift Question

Correct method to save an Int into core data?

I have an entity with an Int16 attribute.

enter image description here

I want to save

var userRepsCount = Int()
which is set by the below stepper method:

@IBAction func userRepsStepper(_ sender: UIStepper) {
userExerciseRepsCounter.text = Int(sender.value).description
self.userRepsCount = Int(sender.value)

I want to add this to the attribute and am using
userExercise.reps = userRepsCount
to do so, however I get the error

Cannot assign value of type 'Int' to type 'Int16'

I was under the impression that Int16 could store int's such as this without issue? What am I missing here?

Answer Source

Try wrapping it with Int16(userRepsCount), and then when you pull it, wrap it with Int(value) before you process it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download