Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 344
infernouk Avatar asked Nov 23 '16 23:11

infernouk


People also ask

How do I save a struct in Core Data?

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.

How do I create a Core Data model?

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.


1 Answers

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

like image 153
Danny Wilson Avatar answered Sep 29 '22 10:09

Danny Wilson