ios - 总体设计——我应该在哪里放置集中访问的对象

标签 ios

我有我的主要应用委托(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/

相关文章:

ios - 如何在 iOS 中实现可以处理多个 API 调用的数据模型?

ios - 触发UIApplicationWillTerminateNotification以“停止” Xcode操作

iphone - 如何将 UIButton 传递给函数并在那里创建...?

iphone - 当文本太大时,文本不会显示在 UILabel 上。

ios - 应用程序被杀死时取消应用程序内购买过程

c# - F# 中的 CGRect - 未定义

ios - 从模态(objective-c)引用呈现 View Controller

ios - 如何使用 Swift 从 JSON 字符串中获取时间?

iOS 应用程序在应用程序设置中未显示位置权限

ios - 出现键盘时 UITableViewController 不 ScrollView