Question: I've found several similar pages that haven't quite been able to address my dilemna. Here goes:

I would like to be able to create a SharedPreferences list in Android that is extractable with an iterator (loop). Somehow I need to be able to add to a list with a key-value of "[Arrayname]+[element\_number]" format. I also need to be able to add/remove values at will. 

-- How will I be able to add to the end if I don't know how long the current SharedPrefs list is?

-- I also need the length of the SharedPrefs list to create arrays from it.

Answer: 
If I understand correctly: No.

If you archive an instance of `B` then when you unarchive it you get an instance of `B`, likewise for instances of `A` and `C`.

However, in non-technical language, a subclass is everything its superclass is *plus* some extra bits. You can't[\*] take an instance of a superclass, created directly or from unarchiving, and make it into an instance of one of its subclasses - the "extra bits" are not there.

HTH

[\*] Before someone comments: Yes, this is not absolutely true in all situations, but you are entering obscure, highly specialised, and dangerous waters. Don't go there.

**Addendum**

Seems you might be in the category where changing the class of an object is safe: you should be able to change the class of an instance to a subclass **provided** the subclass adds no instance variables or properties. To do this you can use the [Objective-C runtime functions](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html):

```
id obj = ... some instance of class A
object_setClass(obj, [B class]); // where B is a subclass of A which adds no properties or variables

```

You can also use the unarchiving classes to set the class.

**Do not do this casually. Consider alternatives, but sometimes it is an appropriate solution.**
The unarchiver wants to create the same type of class that was perviously archived, and that's generally what you want too.

You could look at using `setClass:forClassName:` to change the class that will be unarchived, but you stand a good chance of ruining everything sooner or later...

---

Based on the particle comment:

Another option is to take the superclass instance and 'wrap' it in your subclass instance. So, you can archive and unarchive your subclass instance and it will contain the superclass instance. Any method that your subclass doesn't directly respond to you can forward on to the superclass instance.

In this way you have 2 objects but you aren't tampering with anything or relying on implementation details of classes that you don't own.