Generic parameter 'D' could not be inferred. [OrderBy Error]

87 Views Asked by At

I get an error saying

Generic parameter 'D' could not be inferred Explicitly specify the generic arguments to fix this issue

Maybe because the code was written in swift 3 and now they changed the syntax so if someone can help me with that.

Here is my code:

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

When I remove the OrderBy it works:

Working Code:

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

monitorList Code:

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

There are 1 best solutions below

0
MartinM On BEST ANSWER

That is because the compiler does not know how to infer the type from your OrderBy argument. Looks like you are using CoreStore, add this as a tag and in the description.

To solve your problem build your query chain like that:

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

Also, instead of using "date" as keypathstring you should use \Task.date