I have to store a custom class object to Coredata. The problem is my custom class contains structs,enum etc.I tried following method.
-(void)encodeWit
You should have a custom implementation of the NSCoding protocol in your custom class. In your own implementations of -[initWithCoder:]
and -[encodeWithCoder:]
, you can then encode/decode the struct objects in any way you please.
On way to do this would be to call [coder encodeObject:[NSValue valueWithBytes:&yourStructVariable objCType:@encode(struct YourStructName)] forKey:@"someKey"];
in -[encodeWithCoder:]
and do the equivalent decoding in -[initWithCoder:]
.
You can then just store the class objects as transformable in Core Data.