There is an application that has a list of employees and a list of orders. And when you create an order, a PickerView should appear in the TextField field with a list of employees (with a name). I implement it like this:
- (void)viewDidLoad { NSManagedObjectContext *managedObjectContext = [self managedObjectContext]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Employees"]; self.empl=[[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy]; UIPickerView *picker = [[UIPickerView alloc]init]; picker.dataSource = self; picker.delegate = self; [picker setShowsSelectionIndicator:YES]; [self.empTaskField setInputView:picker]; } #pragma mark - UIPickerView DataSource Method - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return self->_empl.count; } #pragma mark - UIPickerView Delegate Method -(NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ return [_empl objectAtIndex:row]; }
When you click on TextField error appears:
2016-03-27 23: 32: 57.177 Employee Task [2730: 150090] - [Employees copyWithZone:]: unrecognized selector 0x7fcf2ac84fd0 2016-03-27 23: 32: 57.513 Employee Task [2730: 150090] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [Employees copyWithZone:]: unrecognized selector sent to instance 0x7fcf2ac84fd0'
How to solve this problem?
NSManagedObject
and, accordingly, classes inherited from it, do not support theNSCopying
protocol. that is, when you try to makemutableCopy
you come across a method that your Employee does not have. - Max Mikheyenko