Here’s the scenario…
I have several float attributes in my data model which I want to compare against a number of variables (actually the same attributes in another object) and return if any match… straight forward NSPredicate.
However… what I would like to do is to keep track of which of those comparisons evaluate to true and then do a count. I then want to return only the top X results, i.e. those where the most comparisons are true.
Example… (not actual code!!)
object1.float1 = 1;
object1.float2 = 2;
object1.float3 = 3;
object2.float1 = 1;
object2.float2 = 2;
object2.float3 = 4;
object3.float1 = 1;
object3.float2 = 4;
object3.float3 = 4;
float1Variable = 1;
float2Variable = 2;
float3Variable = 3;
kReturnedObjects = 2;
I only want to retrieve object1 and object2.
Any help would be much appreciated, most of my possible solutions so far are incredibly laborious!
What I’d do is define some kind of evaluation-function to calculate the “similarity” of the objects. I.e
The larger
s(obj, comparison_obj)is, the more variables are the same. You can then use Core Data to give you the list ofkReturnedObjectsobjects, sorted bysdescending.