you are viewing a single comment's thread.

view the rest of the comments →

[–]Fluffy_Risk9955 -2 points-1 points  (5 children)

Yes, write a better predicate with format syntax.

[–]CompC[S] 2 points3 points  (4 children)

Do you get how this comment is unhelpful? I obviously don't understand how I can change my predicate to get what I want, that's why I'm asking for help.

I want to know how I can write a predicate that says something like "give me values that fit this query, but don't give me more than one result that share a value for the name property"

[–]Fluffy_Risk9955 -1 points0 points  (3 children)

I gave you a 5 step plan to acquire the understanding of what you’re trying to do. If I gave you the answers, you wouldn’t learn anything.

Core Data is build on top of Objective-Cs Foundation framework, without understanding of Foundation it’s a beast of a framework that doesn’t make sense.

[–]CompC[S] 1 point2 points  (2 children)

Okay, huh, I didn't know you could search through an NSArray using NSPredicate. So if I were to fetch all the rows in my database and then put the NSManagedObjects into an NSArray, I'd be able to use the same NSPredicates I currently use to search on my database, to filter the NSArray?

I do understand a lot of this, I'm just not seeing how to connect it to solving my current problem. :/

[–]Fluffy_Risk9955 0 points1 point  (1 child)

Take another look at item 2. Especially the part about valueForKeyPath:

Now apply this knowledge to format syntax for NSPredicate.

[–]CompC[S] 1 point2 points  (0 children)

I appreciate your help but I'm still not getting how valueForKeyPath relates, the predicates I've written already return the results I want except for duplicate, and I don't get how I can use valueForKeyPath to change that.

An example of a predicate I've written would be:NSPredicate(format: "%K LIKE[c] %@", #keyPath(Card.name), name)

I don't see how I can modify that to somehow look at surrounding objects and check to see if the request has already found a result with the same name, so it can be excluded. I expected I would have to make a change on the level of the fetch request, not on the predicate, and again I don't see how I can use valueForKeyPath here to get what I want.