ios - 构成应用程序数据模型的数组变量最好放在哪里?

标签 ios arrays swift data-modeling

我的名为“Thunder”的 iOS 应用程序越来越复杂,我想知道是否有我不知道的关于数据建模的最佳实践。我不知道在哪里存储我的数组变量。

现在的“Thunder”允许用户录制音频剪辑并将其发布到他们的时间线(主页)。

项目结构(https://github.com/makhfib/Thunder)

    Thunder
    -- AppDelegate
    -- TabBarViewController
    -- Home
    ---- AudioClipViewController
    ---- AudioClipCell
    ---- HomeViewController
    -- Record
    ---- RecordViewController
    -- Library
    ---- LibraryViewController
    -- DataModel
    -- AudioPlayer
    -- AudioClip
      ...

到目前为止,DataModel 保存了包含用户发布的音频剪辑的数组变量。但是,我要添加一个新功能:

Users will be able to add new playlists to their library.

这需要一个数组的数组。但我不知道是否应该继续将我的变量放在 DataModel 中。这个问题听起来可能很愚蠢,但请记住,我正在考虑 future 。我想知道当我的应用程序变胖时如何处理这种情况。

组成应用程序数据模型的数组变量最好放在哪里?为了做出最好的决定,我必须问自己什么?

最佳答案

您的数据模型有什么用?我认为您的模型应该与此类似:

struct UserInfo {
    var playlists: [Playlist]
    // MARK: Other content
}

struct Playlist {
    var clips: [AudioClip]
    // MARK: Other content
}

struct AudioClip {
    // MARK: Content
}

使用这种模型更容易工作,或者保存在数据库中,例如领域或核心数据。

关于ios - 构成应用程序数据模型的数组变量最好放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56912710/

相关文章:

ios - 如何在应用程序委托(delegate)中调用时使 View Controller 动画化

ios - 无效的代码签名权利 - 'previous-application-identifiers' ApplicationLoader 拒绝

ios - 如何访问另一个 ViewController 上的 UITextView

python - 设置数组的 dtypes 时出错

c - 队列类型数据结构使用数组实现

iOS - 在不卡住 UI 的情况下创建大量 UIImageView

xcode - 如何在 Swift 中添加解锁屏幕或使用 TouchID with Security?

iOS TableView 滑动 UIContextualAction 无法获取正确的图像

ios - 找不到 lgcov 的库

objective-c - 如何创建一个c数组?