【发布时间】:2019-11-15 04:05:19
【问题描述】:
我有一个json响应和模型如下
[
{
"name":"Name 1",
"class":"class 1",
"school":"school 1"
},
{
"name":"Name 2",
"class":"class 2",
"school":"school 3"
}
]
及其模型类如下
typealias StudentArray = [Student]
class Student: Codable {
let name: String
let section: String
let school: String
init(name: String, section: String, school: String) {
self.name = name
self.section = section
self.school = school
}
}
我想根据部分过滤整个数组,并为每个部分保留单独的数组。
我还需要保留其他过滤后的数据。
哪个地方最适合它? ViewModel 或 Student Model 类。
【问题讨论】:
-
ViewModel 是我推荐的地方。
-
业务逻辑应该在 Model 中,Presentation 逻辑应该在 ViewModel 中是我知道的合适的方式。
-
Student 是一个对象,它不知道一组 Student [Student],所以肯定在 ViewModel 中。
标签: ios swift mvvm architecture