我说一个错误
无法推断出通用参数'D'明确指定通用参数来解决此问题
也许是因为代码是用swift 3编写的,现在他们更改了语法,以便有人帮助我。
这是我的代码:
listMonitor = dataStack.monitorList(From<Task>(), OrderBy(.descending("date")))
当我删除OrderBy时,它会起作用:
工作代码:
listMonitor = dataStack.monitorList(From<Task>())
monitorList代码:
public func monitorList<D>(_ from: From<D>, _ fetchClauses: [FetchClause]) -> ListMonitor<D> {
CoreStore.assert(
Thread.isMainThread,
"Attempted to observe objects from \(cs_typeName(self)) outside the main thread."
)
return ListMonitor(
dataStack: self,
from: from,
sectionBy: nil,
applyFetchClauses: { fetchRequest in
fetchClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
CoreStore.assert(
fetchRequest.sortDescriptors?.isEmpty == false,
"An \(cs_typeName(ListMonitor<D>.self)) requires a sort information. Specify from a \(cs_typeName(OrderBy<D>.self)) clause or any custom \(cs_typeName(FetchClause.self)) that provides a sort descriptor."
)
}
)
}
答案 0 :(得分:0)
这是因为编译器不知道如何从OrderBy参数推断类型。看起来您正在使用CoreStore,将其添加为标签并在说明中添加。
要解决您的问题,请按以下步骤构建查询链:
listMonitor = dataStack.monitorList(From<Task>().orderBy(.descending("date")))
此外,应该使用\ Task.date
而不是使用“ date”作为键路径字符串