How do I create a custom class from a class that already exists? (Existing class does not support NSCoding)
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 als开发者_如何学Goo 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!
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.
精彩评论