I have entity LoginPass with strings “login” and “pass”. I created registration, and now i need compare if text in my UItextField isEqual with one of the “login” in Core Data. And if such login is created i need compare text in password UITextField and if it’s equal, my app will open main view. I have problem with predicate and i don’t understand how i can initialise new entity with LoginPass * newEntity with using fetchResult
UPDATE: Ok, i will try to understand what i want. My English not good that’s my text isn’t correct. I have Core Data with entity “LoginPass”, consist of “login” (save nickname), “password” (save password for login) and some datas. I need check if nickname in UITextField “login” is contain in Core Data. If there are no such logins will appear alert, and if such login there in Core Data, i will check passwords, and after successful autoresation will appear main View.
//from standart singleton Appdelegate i delegated manageObjectContext
AppDelegate * appDelegate = (AppDelegate *) [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = appDelegate.managedObjectContext;
//assigning. Can I use myEntity in my further mode of action to change datas in entity
NSEntityDescription * myEntity = [NSEntityDescription entityForName:@"LoginPass" inManagedObjectContext:context];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc]init];
//I need search in Core Data with nickname that's in UITextField "login"
NSPredicate *predicateMe = [NSPredicate predicateWithFormat:@"login==%@",login.text];
//login.text - text from UITextField, myEntity.login - string value in key "login" in COre Data
//Or i must write:
NSPredicate *predicateMe = [NSPredicate predicateWithFormat:@"%@ LIKE %@",myEntity.login,login.text];
fetchRequest.predicate = predicateMe;
[fetchRequest setEntity:myEntity];
[fetchRequest setFetchBatchSize:20];
NSSortDescriptor * sortirovka = [[NSSortDescriptor alloc] initWithKey:@"login" ascending:YES];
NSArray * sortArray = [NSArray arrayWithObjects:sortirovka,nil];
[fetchRequest setSortDescriptors:sortArray];
NSFetchedResultsController * fetchResult = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:@"Login"];
//thanks for this part of code, i understand that is must be
NSError *error = nil;
if (![fetchResults performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
//can i use myEntity for changing datas in my "LoginPass" or i need create:
LoginPass *newEntity = ?;
But I don’t understand how to create LoginPass *newEntity for changing datas for user witj nickname, entered in field “login”
Then you perform the fetch:
I am not sure because I’ve not tested it, and I’ve not fully understood your code.But I think it should work.
More here: NSFetchedResultsController Documentation.