Custom object in core data.
Custom object in core data.
- Subject: Custom object in core data.
- From: Todd Freese <email@hidden>
- Date: Mon, 20 Feb 2006 17:18:05 -0600
I am having trouble getting a custom object to save into Core Data. I
have two attributes setup, one that is transient and one that is
undefined. My object supports the NSCoding protocol. Here is my
accessor methods:
- (TimeCodeNumber *)startTimeCode
{
// On-demand get accessor.
[self willAccessValueForKey:@"startTimeCode"];
TimeCodeNumber *timeCodeNumber = [self
primitiveValueForKey:@"startTimeCode"];
[self didAccessValueForKey:@"startTimeCode"];
if (timeCodeNumber == nil) {
NSData *timeCodeNumberData = [self
valueForKey:@"startTimeCodeData"];
if (timeCodeNumberData != nil) {
timeCodeNumber = [NSUnarchiver
unarchiveObjectWithData:timeCodeNumberData];
[self setPrimitiveValue:timeCodeNumber
forKey:@"startTimeCode"];
}
}
return timeCodeNumber;
}
- (void)setStartTimeCode:(TimeCodeNumber *)value
{
// Immediate-Update Set Accessor
[self willChangeValueForKey:@"startTimeCode"];
[self setPrimitiveValue:value forKey:@"startTimeCode"];
[self didChangeValueForKey:@"startTimeCode"];
[self setValue:[NSArchiver archivedDataWithRootObject:value]
forKey:@"startTimeCodeData"];
}
- (NSData *)startTimeCodeData
{
NSData * tmpValue;
[self willAccessValueForKey: @"startTimeCodeData"];
tmpValue = [self primitiveValueForKey: @"startTimeCodeData"];
[self didAccessValueForKey: @"startTimeCodeData"];
return tmpValue;
}
- (void)setStartTimeCodeData:(NSData *)value
{
[self willChangeValueForKey: @"startTimeCodeData"];
[self setPrimitiveValue: value forKey: @"startTimeCodeData"];
[self didChangeValueForKey: @"startTimeCodeData"];
}
When I try to save data into the store, I get the following error:
*** -encodeObject:forKey: only defined for abstract class. Define -
[NSArchiver encodeObject:forKey:]!
Any ideas?
Todd Freese
The Filmworkers Club - Chicago
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden