Elbimio
Elbimio

Reputation: 1041

Independently reusing a declared strong property

I created a class (MyClass) and need several instances of it, each will hold several timers, textfields and labels. Because of ARC, the target was getting deallocated when the timers were invalidated, but I sometimes invalidate them to restart them so I can't let them deallocate. So I went to my AppDelegate (which is the class that creates the instances of MyClass) and declared MyClass as a strong property. @property (strong) MyClass *myInstance; This partially works the problem is that whenever I create another instance, the previous instance loses it's reference, and if I try to restart the NSTimer in an old instance, I get BAD ACCESS. If I restart the last timer there's no problem.

I believe that since myInstance is a property, whenever I make a new one the AppDelegate rewrites the old one, losing the old references. I need to either be able to keep the strong property but somehow make it work independently for each instance, or find another way to make myInstance a strong reference, without it having to be a property.

Upvotes: 0

Views: 54

Answers (1)

anon
anon

Reputation:

Put your instances in a Container like NSSet or NSArray.

Upvotes: 3

Related Questions