CoreStoreObject.where is not working (with Swift 4) #146

Closed
opened 2025-12-29 15:25:31 +01:00 by adam · 5 comments
Owner

Originally created by @athei on GitHub (Jun 11, 2017).

I am trying to use the type safe where clause. This is the code that i first tried:
CoreStore.fetchOne(From<User>(), User.where { $0.isSelf })

Then I get.
Cannot convert value of type 'ValueContainer<V1.User>.Required<Bool>' to closure result type 'Where'

This makes sense because the signature of the closure that CoreStoreObject.where expects is:
(CoreStoreObject) -> Where

I then wrapped the boolean expression to use the boolean constructor of Where :
CoreStore.fetchOne(From<User>(), User.where { Where($0.isSelf.value) })

Then I get an runtime error:

❗ [CoreStore: Assertion Failure] Value.swift:148 value
  ↪︎ Attempted to access values from a 'User' meta object. Meta objects are only used for querying keyPaths and infering types.

I am puzzled how to use this feature. I am using Swift4. Didn't test it with Xcode8. I guess Swift4 is the reason.

Originally created by @athei on GitHub (Jun 11, 2017). I am trying to use the type safe where clause. This is the code that i first tried: `CoreStore.fetchOne(From<User>(), User.where { $0.isSelf })` Then I get. `Cannot convert value of type 'ValueContainer<V1.User>.Required<Bool>' to closure result type 'Where'` This makes sense because the signature of the closure that `CoreStoreObject.where` expects is: `(CoreStoreObject) -> Where` I then wrapped the boolean expression to use the boolean constructor of `Where` : `CoreStore.fetchOne(From<User>(), User.where { Where($0.isSelf.value) })` Then I get an runtime error: ``` ❗ [CoreStore: Assertion Failure] Value.swift:148 value ↪︎ Attempted to access values from a 'User' meta object. Meta objects are only used for querying keyPaths and infering types. ``` I am puzzled how to use this feature. I am using Swift4. Didn't test it with Xcode8. I guess Swift4 is the reason.
adam added the question label 2025-12-29 15:25:31 +01:00
adam closed this issue 2025-12-29 15:25:31 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jun 11, 2017):

@athei Ah, right now the only way you can do this is by writing

User.where { $0.isSelf == true }

I'll think about allowing unary expressions for boolean attributes.

@JohnEstropia commented on GitHub (Jun 11, 2017): @athei Ah, right now the only way you can do this is by writing ```swift User.where { $0.isSelf == true } ``` I'll think about allowing unary expressions for boolean attributes.
Author
Owner

@athei commented on GitHub (Jun 11, 2017):

Okay did not expect that it was implemented as an overloaded operator. You can't cmd+click these operators :/. Really hard to find the implementation.

@athei commented on GitHub (Jun 11, 2017): Okay did not expect that it was implemented as an overloaded operator. You can't cmd+click these operators :/. Really hard to find the implementation.
Author
Owner

@JohnEstropia commented on GitHub (Jun 11, 2017):

I also just realized the README didnt't have documentation on these yet, sorry about that.
In the meantime there are sample usages in the source code documentation in the CoreStoreObject+Querying.swift file that you can refer to, as well as unit test cases in the DynamicModelTests.swift file.

@JohnEstropia commented on GitHub (Jun 11, 2017): I also just realized the README didnt't have documentation on these yet, sorry about that. In the meantime there are sample usages in the source code documentation in the **CoreStoreObject+Querying.swift** file that you can refer to, as well as unit test cases in the **DynamicModelTests.swift** file.
Author
Owner

@athei commented on GitHub (Jun 11, 2017):

No need to apologise. I would recommend adding one sentence describing that unary is not possible because of the operator implementation.

I guess this can be closed now.

@athei commented on GitHub (Jun 11, 2017): No need to apologise. I would recommend adding one sentence describing that unary is not possible because of the operator implementation. I guess this can be closed now.
Author
Owner

@JohnEstropia commented on GitHub (Jun 11, 2017):

Thanks for your feedback!

@JohnEstropia commented on GitHub (Jun 11, 2017): Thanks for your feedback!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#146