我有带有字符串“login”和“pass”的实体 LoginPass。我创建了注册,现在我需要比较我的 UItextField isEqual 中的文本是否与 Core Data 中的“登录”之一。如果创建了这样的登录,我需要比较密码 UITextField 中的文本,如果它相等,我的应用程序将打开主视图。我对谓词有疑问,我不明白如何使用 fetchResult 使用 LoginPass * newEntity 初始化新实体
更新:好的,我会试着理解我想要什么。我的英语不好那是我的文字不正确。我有实体“LoginPass”的核心数据,由“登录”(保存昵称)、“密码”(保存登录密码)和一些数据组成。我需要检查 UITextField“登录”中的昵称是否包含在核心数据中。如果没有这样的登录会出现警报,如果在 Core Data 中有这样的登录,我会检查密码,并且在成功自动恢复后会出现主视图。
//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 = ?;
但我不明白如何创建 LoginPass *newEntity 以更改用户 witj 昵称的数据,输入字段“登录”