Hi all,
I'm implementing a "DetailedUserView" for the Dore Data challenge part (day 61)
This view contains a generic FilteredList (form Core Data technique project, Project 12 part 2) for Friends of the current User.
To this list I will pass a predicate to retrieve from database the complete information for all Friends, so in the init for my DetailedUserView I prepare everything I need to pass dow to this generic list view:
struct DetailedUserView: View {
@State private var activeFriendsOnly = false
private let user: CDUser
private let friendsID: [UUID]
private let friendsPredicate: NSPredicate
init(activeFriendsOnly: Bool = false, user: CDUser) {
self.user = user
self.friendsID = user.wrFriends.map{ $0.wpId }
self.friendsPredicate = NSPredicate(format: "wpID IN %@", argumentArray: friendsID)
self.activeFriendsOnly = activeFriendsOnly
}
var body: some View {
...
(wr and wp prefixes indicate that these are wrapping-computed-properties/relationship to not deal with the optionals from Core Data, as in Creating NSManagedObject subclasses, added as extensions to the generated cclasses)
The probem is that the app crashes when entering the DetailUserView with the error:
unimplemented SQL generation for predicate : (wpID IN 3E6FA1D2-527C-41E9-9DA0-2D89EB0B8D6A)'
The example for this type of predicate is at https://nspredicate.xyz/#predicate-format-and-arguments
Examples
Is included in an Array of values
let wantedItemIDs = [1, 2, 3, 5, 8, 13, 21]
// Retrieve record with item_id which is inside the wantedItemIDs array
let inclusivePredicate = NSPredicate(format: "item_id IN %@", wantedItemIDs)
Curiously:
if I use the predicate from the example above (without the label argumentArray:) I got the error:
NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (wpID IN {3E6FA1D2-527C-41E9-9DA0-2D89EB0B8D6A, 29E0F9EE-71F2-4043-AD36-9D2D6789B2C8, 8BE513E0-B46D-40CC-B617-A295A26525DE})'
which seems to consider the whole array...
...but if I use the Predicate with the label argumentArray: I get the error:
'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (wpID IN 3E6FA1D2-527C-41E9-9DA0-2D89EB0B8D6A)'
which seems to consider ony the first element of the array :-)
I tried also with strings (converting the UUID or using user name) but I always get this error.
Did anyone met and solved this error?
Is there another simple way to filter Core Data objects to fetch only those with an attribute value contained in an array/set/collection ?
I can give acess to my complete code on gitHub if needed (not public by defaut because I'm, code-shy:-)), let me know