Can I search for an existing instance of a particular class in Swift in runtime?

I realize I could declare a global var, such as:

var mySpecialSubClass : MySpecialSubClass?

..and then check if it is defined.

Don't know of any reason to do one way or another, but I was wondering if there was a search for an instance of "MySpecialSubClass" function or method available?

Do you mean searching in Xcode (that's easy) or at runtime (why would you need ?)

What would be the purpose ?

You could set some global counter in the init of the class. This way, you would know that there are instances.

Or read ARC counter of a specific object: https://medium.com/@subhangdxt/how-to-check-objects-reference-count-swift-675fbb9441d8

Can I search for an existing instance of a particular class in Swift in runtime?
 
 
Q