I would like to take a singleton class that gets used by multiple view controllers, copy it, and save it to an array that will be displayed in another view controller with a table view that will show multiple instances of that class. This array will eventually be archived to be retrieve with the same data.
Before I attempt this, is there a way I can duplicate this singleton instance, save it to the array, re-initialize it for the next use, and so on (without getting the same exact previously uninitialized object)?
It’s not a singleton that you want.
A singleton
must alwaysreturn thesame instance.What you want is a normal class that maybe have a convenience class method to feed you some pre-populated object.
If it’s possible to create more than one instance of an object it’s not a singleton anymore.
But your singleton class could hold a variable amount of instance of other class that you wish to display.
So in that way what you are asking could be possible, but without the copy part on the singleton.
you can have a
singletonclass that would hold an array of an other class. So you could call yoursingletonlike thisIn your
newOtherClassInstancePleasemethod you implement the necessary thing to store that new object into an array, that you can distribute like thisOr NSMutableArray if you prefer.
With that you would be able to share, create new and even delete object. if you implement the necessary method on your singleton.
But again don’t copy a singleton, if the singleton is well implemented sending it a copy call should throw an exception, or return the single singleton instance that exists.