【发布时间】:2018-10-01 05:27:48
【问题描述】:
我正在使用完成处理程序进行异步调用,该处理程序通过查询为我获取数据。这些查询可能因用户操作而异。
我的数据调用如下所示;
class DataManager {
func requestVideoData(query: QueryOn<VideoModel>, completion: @escaping (([VideoModel]?, UInt?, Error?) -> Void)) {
client.fetchMappedEntries(matching: query) { (result: Result<MappedArrayResponse<FRVideoModel>>) in
completion(videos, arrayLenght, nil)
}
}
}
我的 ViewController 是这样的;
DataManager().requestVideoData(query: /*One of the queries below*/) { videos, arrayLength, error in
//Use the data fetched based on the query that has been entered
}
我的查询如下所示;
let latestVideosQuery = QueryOn<FRVideoModel>().limit(to: 50)
try! latestVideosQuery.order(by: Ordering(sys: .createdAt, inReverse: true))
还有这个;
let countryQuery = QueryOn<FRVideoModel>()
.where(valueAtKeyPath: "fields.country.sys.contentType.sys.id", .equals("country"))
.where(valueAtKeyPath: "fields.country.fields.countryTitle", .includes(["France"]))
.limit(to: 50)
但我不完全确定如何以正确的方式实现这些查询,以便它们与 MVC 模型相对应。
我正在考虑 DataManager 类中的 switch 语句,并将一个值传递给我的 ViewController 上的查询参数,这将导致对 fetchMappedEntries() 的正确调用。唯一的问题是我仍然需要根据我在 VC 中的查询执行正确的函数,所以我还需要一个 switch 语句。
或者我需要在我的 ViewController 中包含我的所有查询吗?我认为这是不正确的,因为它似乎应该在我的模型中。
【问题讨论】:
-
就我个人而言,我认为你应该让这个工作正常进行,不要再担心“正确的方法,以便它们与 MVC 模型相对应”,无论这意味着什么。
标签: ios swift tvos contentful