我有我的主要应用委托(delegate) 我有一些由 Storyboard 驱动的 UIViewController 派生实例
假设我想为我的应用程序提供一个集中的持久层——也许是 SQLite 的核心数据。我会把那些东西放在哪里?我缺少一些可以从所有 UIViewController 实例访问的可集中访问的“应用程序”类。
这里有一个可遵循的模式吗?
最佳答案
你应该检查 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.
这里是一个示例实现的来源:What should my Objective-C singleton look like?
这是现代解决方案的直接链接: https://stackoverflow.com/a/145395/644629
关于ios - 总体设计——我应该在哪里放置集中访问的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11634056/