Error with NSPredicate #352

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

Originally created by @TheJustikar on GitHub (Dec 17, 2020).

Hi,

I have 2 entities, Match and Player, both CoreStoreObject's. Match has 2 relationships to Player called winners and losers (and respective inverses in Player).

When trying to filter the matches with this Where:

let players: [Player] = ...
Where<Match>(NSPredicate(format: "(ANY winners IN %@) OR (ANY losers IN %@)", players, players))

I get this error:

2020-12-17 23:37:35.782071+0100 APP_NAME[7234:510265] *** NSForwarding: warning: object 0x600003a64bb0 of class 'APP_NAME.Player' does not implement methodSignatureForSelector: -- trouble ahead
Unrecognized selector -[APP_NAME.Player longLongValue]
2020-12-17 23:37:35.782436+0100 APP_NAME[7234:510265] Unrecognized selector -[APP_NAME.Player longLongValue]
Unrecognized selector -[APP_NAME.Player longLongValue]

I tested this predicate without CoreStore and it works.

Originally created by @TheJustikar on GitHub (Dec 17, 2020). Hi, I have 2 entities, `Match` and `Player`, both `CoreStoreObject`'s. `Match` has 2 relationships to `Player` called `winners` and `losers` (and respective inverses in `Player`). When trying to filter the matches with this `Where`: ``` let players: [Player] = ... Where<Match>(NSPredicate(format: "(ANY winners IN %@) OR (ANY losers IN %@)", players, players)) ``` I get this error: ``` 2020-12-17 23:37:35.782071+0100 APP_NAME[7234:510265] *** NSForwarding: warning: object 0x600003a64bb0 of class 'APP_NAME.Player' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[APP_NAME.Player longLongValue] 2020-12-17 23:37:35.782436+0100 APP_NAME[7234:510265] Unrecognized selector -[APP_NAME.Player longLongValue] Unrecognized selector -[APP_NAME.Player longLongValue] ``` I tested this predicate without `CoreStore` and it works.
adam added the enhancement label 2025-12-29 15:29:49 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Dec 19, 2020):

@TheJustikar Thanks for reporting. I'll add an enhancement for this in a future update, but for now you'll need to extract the NSManagedObjects since NSPredicates don't know how to interpret CoreStoreObjects. Please try:

let players: [Player] = // ...
Where<Match>(
    "(ANY winners IN %@) OR (ANY losers IN %@)", 
    players.map {  $0.cs_toRaw() },
    players.map {  $0.cs_toRaw() }
)
@JohnEstropia commented on GitHub (Dec 19, 2020): @TheJustikar Thanks for reporting. I'll add an enhancement for this in a future update, but for now you'll need to extract the `NSManagedObject`s since `NSPredicate`s don't know how to interpret `CoreStoreObjects`. Please try: ```swift let players: [Player] = // ... Where<Match>( "(ANY winners IN %@) OR (ANY losers IN %@)", players.map { $0.cs_toRaw() }, players.map { $0.cs_toRaw() } ) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#352