对于多对多的关系:property =;期望的类型= NSSet;给定类型

时间:2017-07-11 11:52:28

标签: ios core-data one-to-many

我尝试在核心数据中增加价值。但点击提交按钮后,应用程序崩溃并显示错误,如:

  

for to-many relationship:property =" roshan&#34 ;;期望的类型= NSSet;   给定类型=唯一; value =(实体:唯一;   id:0x60800022fd60    ;数据:   {       abc =(       );       number = nil;       study =零; })'

- (IBAction)submitData:(id)sender {
    AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

    NSManagedObjectContext *context = [appDelegate manageObjectContext];
    Resgistration *newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Resgistration" inManagedObjectContext:context];
    //newContact = [NSEntityDescription insertNewObjectForEntityForName:@"Resgistration" inManagedObjectContext:context];
    Unique *number = [NSEntityDescription insertNewObjectForEntityForName:@"Unique" inManagedObjectContext:context];

    //number = [NSEntityDescription insertNewObjectForEntityForName:@"Unique" inManagedObjectContext:context];

    [number setValue:_numberText.text forKey:@"number"];
    [number setValue:_studyText.text forKey:@"study"];
    NSMutableSet *roshanSet = [[NSMutableSet alloc] init];
    [roshanSet addObject:number];
    [newContact addRoshan:roshanSet];
    [newContact setValue:number forKey:@"roshan"];
    [newContact setValue:_numberText.text forKey:@"number"];
    [newContact setValue:_nameText.text forKey:@"name"];
    [newContact setValue:_addressText.text forKey:@"address"];
    [newContact setValue:_emailText.text forKey:@"email"];
    [newContact setValue:_othernoText.text forKey:@"otheNo"];
    [newContact setValue:_hobbyText.text forKey:@"hobby"];
    [newContact setValue:_contactText.text forKey:@"contact"];
    NSError *error;
    [context save:&error];

    _nameText.text = @"";
    _addressText.text = @"";
    _emailText.text = @"";
    _othernoText.text = @"";
    _hobbyText.text = @"";
    _contactText.text = @"";
    _numberText.text = @"";

    TableViewController *table = [self.storyboard instantiateViewControllerWithIdentifier:@"TableViewController"];
    [self.navigationController pushViewController:table animated:YES];
}

0 个答案:

没有答案