views:

43

answers:

1

Hey all!

What I'm trying to do is convert an EKEvent into NSData, and then convert it back into an EKEvent.

I looked around and noticed that in order to use NSKeyedArchiver, the class must conform to the NSCoding protocol. I also found that if I was creating a custom class, I could make it conform to the NSCoding protocol by implementing encodeWithCoder: on such a custom class.

Essentially, I assume that in order to convert my EKEvent to NSData and back, I will need to create a custom class (let us call it CustomEvent) I need to do the following:

EKEvent --> CustomEvent --> NSData --> CustomEvent --> EKEvent

Can I get any help on learning how to create a custom class which DUPLICATES an existing class with the exception that I implement encodeWithCoder: to make it conform to NSCoding?

I'm looking at EKEvent.h, and I know that it involves other classes which I must also duplicate (because they too don't conform to NSCoding). Can anyone send me a tutorial link or help me out?

Thanks in advance!

A: 

What you're describing appears to be a subclass.

However, in Objective-C, you have the simpler option of defining a category on an existing class to add the functionality you want.

Chuck
Perfect! Exactly what I was looking for. So I've created the .m and .h, But I still don't know how I should handle the following:EKEvent has a few objects, such as: NSDate *_dateStamp;So when I define - (void)encodeWithCoder:(NSCoder *)coder, from Apple Documentation (regarding custom subclasses) I see that I should put: [coder encodeObject:dateStamp forKey:@"dateStamp"];of course, XCode complains that the "dateStamp" object does not exist (because it is not declared in the Category). Do I just re-declare? Would there be a problem with that (I assume there would)?
Jus' Wondrin'
The name of the field is `_dateStamp`, not `dateStamp`, and as long as you're importing the header, it should be visible. However, I would be careful not to run afoul of implementation details that might change in the future.
Chuck