I have some doubts regarding storing plain "int" or "short" (int16_t) attributes inside the "Core Data" data management framework (on iOS 6 in my case). I tried using it various ways and found it impossible to do, failing with the above mentioned exception. Now, a few weeks later, I found this article inside StackOverflow and it looks like someone does exactly that:
See following example for storing an Enumeration in the lower answer from "Daniel Eggert": Best way to implement Enums with Core Data
Here it looks as if he uses a plain "int16_t" and maps it to a "Core Data" entry "Integer 16" inside the data model... does this really work? I tried it exactly as stated (even using the same naming :-)) and it fails with the well known "EXC_BAD_ACCESS" exception... as expected.
Any thoughts on this one? Did I misinterpret the linked answer?
---- Edit: --- Interesting how someone rates this question (that even properly links another question) down, but doesn't have an answer?! Anyway:
I now tried the very same with the "Event" sample application from Apple and it works. My own test doesn't work, still. Main difference between the apps:
- My managed class is not auto-generated, I reused an existing class
- I still have some properties with "@synthesize" in my existing class
My own entity (managed object): h:
@interface TestEntity : NSManagedObject
{
}
@property (nonatomic) int64_t testAttribute;
@end
m:
@dynamic testAttribute;
model data type: "Integer 64".
other.m:
TestEntity *testEntity = (TestEntity *)[NSEntityDescription insertNewObjectForEntityForName:@"Trip" inManagedObjectContext:[GenericDAO getManagedContext]];
[testEntity setTestAttribute : 4]; //this triggers the exception