Reference to member 'sum' cannot be resolved without a contextual type #248

Open
opened 2025-12-29 15:27:33 +01:00 by adam · 1 comment
Owner

Originally created by @asadali737 on GitHub (Dec 27, 2018).

I was using CoreStore for a very long time. Today I just updated in to the newest version. It things get little bit complicated for me. I am unable to resolve the error.

This is my class, according to new CoreStore version.

class Temp: CoreStoreObject {
    
    let abc = Value.Required<String>("abc", initial: "")
    let xyz = Value.Required<Int>("xyz", initial: 0)
}

Now somewhere in code I need to get sum of xyz from database. I read the docs and following is the code for it.

let sum = transaction.queryValue(From<Temp>().select(.sum(\Temp.xyz)))

But I am getting following error on this line. Please help me to solve it.

Reference to member 'sum' cannot be resolved without a contextual type

Cocoa Pod version: 1.5.3
CoreStore version: 5.3.1

Previously I was using following code to get the sum
if let sum = transaction.queryValue(From<Temp>(), Select<Int>(.sum("xyz")), Where("abc = ' '")) { }

Originally created by @asadali737 on GitHub (Dec 27, 2018). I was using CoreStore for a very long time. Today I just updated in to the newest version. It things get little bit complicated for me. I am unable to resolve the error. This is my class, according to new CoreStore version. ``` class Temp: CoreStoreObject { let abc = Value.Required<String>("abc", initial: "") let xyz = Value.Required<Int>("xyz", initial: 0) } ``` Now somewhere in code I need to get sum of `xyz` from database. I read the docs and following is the code for it. `let sum = transaction.queryValue(From<Temp>().select(.sum(\Temp.xyz)))` But I am getting following error on this line. Please help me to solve it. `Reference to member 'sum' cannot be resolved without a contextual type` Cocoa Pod version: 1.5.3 CoreStore version: 5.3.1 Previously I was using following code to get the sum `if let sum = transaction.queryValue(From<Temp>(), Select<Int>(.sum("xyz")), Where("abc = ' '")) { }`
adam added the in progressquestion labels 2025-12-29 15:27:33 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jan 16, 2019):

Sorry I missed responding to this. Looks like I missed adding a generic-resolved method for this. For now you can try writing

if let sum = transaction.queryValue(
    From<Temp>()
        .select(Int.self, .sum(\.xyz)) // Note the first argument
        .where(\.abc == " ")
)
@JohnEstropia commented on GitHub (Jan 16, 2019): Sorry I missed responding to this. Looks like I missed adding a generic-resolved method for this. For now you can try writing ```swift if let sum = transaction.queryValue( From<Temp>() .select(Int.self, .sum(\.xyz)) // Note the first argument .where(\.abc == " ") ) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#248