【问题标题】:Generic parameter 'D' could not be inferred. [OrderBy Error]无法推断通用参数“D”。 [订购错误]
【发布时间】:2019-08-22 13:29:34
【问题描述】:

我收到一个错误提示

无法推断通用参数“D”显式指定通用参数以解决此问题

也许是因为代码是用 swift 3 编写的,现在他们改变了语法,所以如果有人可以帮助我的话。

这是我的代码:

listMonitor = dataStack.monitorList(From<Task>(), OrderBy(.descending("date")))

当我删除 OrderBy 时,它可以工作:

工作代码:

listMonitor = dataStack.monitorList(From<Task>())

监控列表代码:

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."
            )
        }
    )
}

【问题讨论】:

  • 你的监视器列表里面有什么
  • 可以添加monitorList函数的声明吗?
  • @guru 我用 monitorList 代码更新代码
  • @Kolineal 我用 monitorList 代码更新代码

标签: ios arrays swift xcode corestore


【解决方案1】:

这是因为编译器不知道如何从您的 OrderBy 参数推断类型。看起来您正在使用 CoreStore,请将其添加为标签并在描述中。

要解决您的问题,请像这样构建您的查询链:

listMonitor = dataStack.monitorList(From<Task>().orderBy(.descending("date")))

此外,您应该使用 \Task.date

而不是使用“日期”作为键路径字符串

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 2018-03-31
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多