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?

Replies

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

Add a Comment

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

  • Did most of my work in Windows, that had such a feature, so am looking for an equivalent.

    But also, there might be a case of searching through multiple instances to find a particular one maybe?

Add a Comment