构成应用程序数据模型的数组变量最好放在哪里?
Where is best to place the array variables that make up my app's data model?
我的名为 'Thunder' 的 iOS 应用程序越来越复杂,我想知道是否有我不知道的关于数据建模的最佳实践。我不知道在哪里存储我的数组变量。
'Thunder',就像现在一样,允许用户录制音频剪辑并将其发布到他们的时间线 (Home
)。
项目结构(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
。这个问题听起来可能很愚蠢,但请记住,我正在考虑未来。我想知道当我的应用程序变胖时如何处理这种情况。
组成应用程序数据模型的数组变量最好放在什么地方?为了做出最好的决定,我必须问自己什么?
您的数据模型有什么用?我认为您的模型应该与此类似:
struct UserInfo {
var playlists: [Playlist]
// MARK: Other content
}
struct Playlist {
var clips: [AudioClip]
// MARK: Other content
}
struct AudioClip {
// MARK: Content
}
使用这种模型更容易工作,或保存在数据库中,例如领域或核心数据。
我的名为 'Thunder' 的 iOS 应用程序越来越复杂,我想知道是否有我不知道的关于数据建模的最佳实践。我不知道在哪里存储我的数组变量。
'Thunder',就像现在一样,允许用户录制音频剪辑并将其发布到他们的时间线 (Home
)。
项目结构(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
。这个问题听起来可能很愚蠢,但请记住,我正在考虑未来。我想知道当我的应用程序变胖时如何处理这种情况。
组成应用程序数据模型的数组变量最好放在什么地方?为了做出最好的决定,我必须问自己什么?
您的数据模型有什么用?我认为您的模型应该与此类似:
struct UserInfo {
var playlists: [Playlist]
// MARK: Other content
}
struct Playlist {
var clips: [AudioClip]
// MARK: Other content
}
struct AudioClip {
// MARK: Content
}
使用这种模型更容易工作,或保存在数据库中,例如领域或核心数据。