close

How to search if a values exist in core data entity using magical records

QuestionsCategory: iOS (iPhone, iPad)How to search if a values exist in core data entity using magical records
Amman Ullah asked 8 months ago

How to search for a specific value in core data using magical records? It’s like searching records.

1 Answers
Chaudhary Talha Staff answered 7 months ago

You can do that by

MR_findFirstWithPredicate

 You can either find it by predicate or via a simple value. Suppose I have an entity called FavCPT.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"cptName == %@ && modifier == %@ && dx1 == %@ && dx2 == %@ && dx3 == %@ && dx4 == %@",cptName,modi,dx1,dx2,dx3,dx4];
FavCPT *foundCPT = [FavCPT MR_findFirstWithPredicate:predicate sortedBy:@"cptName" ascending:YES];

Note that the names like cptName, Modifier are the one I have in NSManagedObject Subclass i.e. 
FavCPT+CoreDataProperties.h The second way is to simply check the value exist against an attribute. But you can’t check multiple values in this way.

FavCPT *foundCPT = [FavCPT MR_findFirstByAttribute:@"cptName" withValue:cell.DXCodeName.text];

x
Like what we are doing? Join Us! Become a contributor at iOS Pakistan.