0

I am using an Objective c class, a subclass of NSObject. This class cannot be modified. I have an instance of this class that I wish to write to a file which can be retrieved and later reinstate. The object does not conform to NSCoding.

To sum up, I need to save an instance of a class to a file which can be retrieved later, without using any of the NSCoding methods such as NSKeyedArchiving encodeWithCoder ...

Using them returns this... NSInvalidArgumentException ...encodeWithCoder:] unrecognised selector sent to instance...

Is there any other way I can store this object for later use Thank you

p.s The class is a UIEvent

123hal321
  • 2,080
  • 4
  • 24
  • 25
  • 2
    Could you explain to us why you want to archive an event? The reason that UIEvent doesn't conform to NSCoding is that it's not ordinarily thought of as data that would need to be persistent. – NSResponder Apr 08 '10 at 17:00
  • I'm with NSResponder. Sounds like you are trying to do something that would be better be handled in some other way which would not involve archiving UIEvents. – Jaanus Apr 08 '10 at 18:47

2 Answers2

2

Can you subclass the class and implement the NSCoding protocol in the subclass?

Jaanus
  • 17,688
  • 15
  • 65
  • 110
  • Thank you but the class has many internal members that do not support NSCoding either and the class cannot be subclassed – 123hal321 Apr 08 '10 at 16:22
0

Depending on what the object has as members, you could create a dictionary, and set each member's value as a key in the dictionary and then write that to file.

However, I don't understand why you can't subclass the object and implement the NSCoding protocol, as Jaanus suggested?

Jasarien
  • 58,279
  • 31
  • 157
  • 188
  • The members do not support NSCoding and the I cannot subclass the class, I was wondering if there were some relatively low level C function to copy it from memory or something like that?? I cannot access some of the objects properties as they are private – 123hal321 Apr 08 '10 at 16:27
  • Is there anyway to do this without NSCoding at all – 123hal321 Apr 08 '10 at 16:47
  • **WHY** can't you subclass the class? What is preventing that? – Jasarien Apr 08 '10 at 23:22