I have an entity with an Int16 attribute.
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?
There are two steps to storing an array of a custom struct or class in Core Data. The first step is to create a Core Data entity for your custom struct or class. The second step is to add a to-many relationship in the Core Data entity where you want to store the array.
Add a Core Data Model to an Existing ProjectChoose File > New > File and select the iOS platform tab. Scroll down to the Core Data section, select Data Model, and click Next. Name your model file, select its group and targets, and click Create.
Try wrapping it with Int64(userRepsCount)
, and then when you pull it, wrap it with Int(value)
before you process it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With