我需要创建一个全局对象,该对象可以工作并且可以在程序中的所有类中使用。我做了一些研究,发现该解决方案似乎是在 AppDelegate 中实现的,但似乎没有太多关于如何实现这一点的解释,更重要的是,根据我的理解,这似乎并不正确AppDelegate 的目的。
最佳答案
您应该检查singleton pattern :
In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects. The term comes from the mathematical concept of a singleton.
关于ios - 创建跨类的全局对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11608104/