Pétur Ingi Egilsson
Pétur Ingi Egilsson

Reputation: 4452

How can I determine the attribute data type of an entity in Core Data?

In Core Data I have an entity called item which has the the attribute score.

Currently score has the type int16_t.

scores value is updated from different places within the project, by parsing it via [[UITextField text] integerValue], while keeping an open eye for overflow.

scores datatype is very likely to change in the future. I want to minimise future risk associated with that change.

The only way I can think of is by the preprocessor macro #define itemScore_t int16_t.

Is there a better way, such as determining the datatype directly from Core Data?

Upvotes: 1

Views: 123

Answers (1)

Wain
Wain

Reputation: 119031

Using NSEntityDescription you can navigate to the particular attribute and get the NSAttributeDescription, from there you can get the attributeType (which gives NSInteger16AttributeType / NSInteger32AttributeType / NSInteger64AttributeType).

Upvotes: 3

Related Questions