T. Eddy T. Eddy - 1 year ago 92
iOS Question

How can open variables in shared frameworks have different values?

From what I understand, the standard frameworks on iOS devices (UIKit, AVKit, etc) are essentially dynamic shared libraries.

If these libraries are shared between multiple applications, how can an open variable (such as UIApplication.shared) have a different value for each application?

The only solutions I see are if the libraries were infact statically linked and not dynamically, or if the shared library has its own memory space in the application and doesn't have heap space in another part of the system's memory which is shared.

Answer Source

The libraries you are referring to are all singletons. That is, an instance of the class instantiated only once and is globally accessible (within your own app).

In this pattern a variable in the class, say UIApplication.shared, is a lazily instantiated instance of UIApplication. Since these libraries are written in objective-c they won't be created like this, but in swift it looks like this:

class UIApplication {

    static var shared = UIApplication()


What this means with regards to your question is that these instances only exist within your application, instantiated when you call UIApplication.shared, and are destroyed when your application finishes running. They do not share anything with other applications, otherwise all hell would break loose haha

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download