핵심 데이터에 개체를 추가하려고했습니다. 그래서, 핵심 데이터 저장소에 중복 항목을 허용하지 않아야합니다. 그렇게하는 방법? 이것은 데이터 저장 관련 코드입니다.핵심 데이터에 중복 항목을 제한 할 수있는 방법이 있습니까?
-(IBAction)save:(id)sender
{
if([name.text isEqualToString:@""] && [address.text isEqualToString:@""] && [phone.text isEqualToString:@""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yo..!"
message:@"Data Not Saved"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
coreDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *newContact;
newContact = [NSEntityDescription
insertNewObjectForEntityForName:@"Contacts"
inManagedObjectContext:context];
[newContact setValue:name.text forKey:@"name"];
[newContact setValue:address.text forKey:@"address"];
[newContact setValue:phone.text forKey:@"phone"];
name.text = @"";
address.text = @"";
phone.text = @"";
NSError *error;
[context save:&error];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yo..!"
message:@"Data Saved"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
NSLog(@"Object Saved\n");
}
}
저장하는 동안
https://developer.apple.com/library/content/samplecode/ThreadedCoreData/Introduction/Intro.html
는 확인합니다. 기존의 경우 그냥 업데이트. 새 항목을 만들고 DB에 저장하지 않으려면 – Meera