Originally created by @manmal on GitHub (Oct 18, 2019).
Hi, first of all, thanks for the great work. This is one of the cleanest and most innovative Swift libraries I've seen.. e.g. the keypath handling is mind boggling :)
I'm having an issue using keypaths for Where clauses on entity subclasses (the Animal > Dog situation), namely when querying fields that reside in the super object. This affects not only Where clauses, but for simplicity I picked this example. I isolated it and made a demo project demonstrating the issue. But I think you just need this piece of code:
importCoreStoreimportFoundationclassAnimal:CoreStoreObject{letanimalProperty=Value.Required<String>("animalProperty",initial:"initial")}classDog:Animal{letdogProperty=Value.Required<String>("dogProperty",initial:"initial")}structFetcher{// WorksstaticfuncfetchDogByDogProperty()throws->Dog?{returntryCoreStore.fetchOne(From<Dog>().where(\.dogProperty=="query"))}// Error "Type of expression is ambiguous without more context" in line 26staticfuncfetchDogByAnimalProperty()throws->Dog?{returntryCoreStore.fetchOne(From<Dog>().where(\.animalProperty=="query"))}// Error "Cannot convert value of type 'Where<Animal>' to expected argument type 'Where<_>'" in line 34staticfuncfetchDogByAnimalPropertyTry2()throws->Dog?{returntryCoreStore.fetchOne(From<Dog>().where(\Dog.animalProperty=="query"))}}
I'm using Xcode 11 with Swift 5.
Originally created by @manmal on GitHub (Oct 18, 2019).
Hi, first of all, thanks for the great work. This is one of the cleanest and most innovative Swift libraries I've seen.. e.g. the keypath handling is mind boggling :)
I'm having an issue using keypaths for `Where` clauses on entity subclasses (the `Animal` > `Dog` situation), namely when querying fields that reside in the super object. This affects not only Where clauses, but for simplicity I picked this example. I isolated it and made a demo project demonstrating the issue. But I think you just need this piece of code:
```swift
import CoreStore
import Foundation
class Animal: CoreStoreObject {
let animalProperty = Value.Required<String>("animalProperty", initial: "initial")
}
class Dog: Animal {
let dogProperty = Value.Required<String>("dogProperty", initial: "initial")
}
struct Fetcher {
// Works
static func fetchDogByDogProperty() throws -> Dog? {
return try CoreStore.fetchOne(
From<Dog>()
.where(\.dogProperty == "query")
)
}
// Error "Type of expression is ambiguous without more context" in line 26
static func fetchDogByAnimalProperty() throws -> Dog? {
return try CoreStore.fetchOne(
From<Dog>()
.where(\.animalProperty == "query")
)
}
// Error "Cannot convert value of type 'Where<Animal>' to expected argument type 'Where<_>'" in line 34
static func fetchDogByAnimalPropertyTry2() throws -> Dog? {
return try CoreStore.fetchOne(
From<Dog>()
.where(\Dog.animalProperty == "query")
)
}
}
```
I'm using Xcode 11 with Swift 5.
adam
added the question label 2025-12-29 15:28:15 +01:00
@manmal Yes, this is a known limitation with how KeyPaths work.
For these cases, you can use the closure version instead:
.where({$0.animalProperty=="query"})
@JohnEstropia commented on GitHub (Oct 18, 2019):
@manmal Yes, this is a known limitation with how `KeyPath`s work.
For these cases, you can use the closure version instead:
```swift
.where({ $0.animalProperty == "query" })
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @manmal on GitHub (Oct 18, 2019).
Hi, first of all, thanks for the great work. This is one of the cleanest and most innovative Swift libraries I've seen.. e.g. the keypath handling is mind boggling :)
I'm having an issue using keypaths for
Whereclauses on entity subclasses (theAnimal>Dogsituation), namely when querying fields that reside in the super object. This affects not only Where clauses, but for simplicity I picked this example. I isolated it and made a demo project demonstrating the issue. But I think you just need this piece of code:I'm using Xcode 11 with Swift 5.
@JohnEstropia commented on GitHub (Oct 18, 2019):
@manmal Yes, this is a known limitation with how
KeyPaths work.For these cases, you can use the closure version instead:
@manmal commented on GitHub (Oct 18, 2019):
Thank you @JohnEstropia !