Olex
Olex

Reputation: 1656

Set NSManagedObject to nil;

By tapping a cell in tableView I am creating new NSManagedObject instance and do rollback to the previous viewController:

User *user = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self.delegate setSupervisorGUID:user.server_id supervisorTitle:user.name];
[self.navigationController popViewControllerAnimated:YES];

at the same viewController I have a cancel button what else rollback to the previous viewController but without setting new object (zeroing User object):

[self.delegate setSupervisorGUID:[NSNull null] supervisorTitle:@"User not set"];
[self.navigationController popViewControllerAnimated:YES];

This way does the trick but I think it's logically incorrect and I also have a warning here. How can I do this in right way?

UPDATE

warning is:

Incompatible pointer types sending 'NSNull *' to parameter of type 'NSString *'

Here is the definition of -setSupervisorGUID:supervisorTitle:

- (void) setSupervisorGUID:(NSString *) supervisorId supervisorTitle:(NSString *) supervisorTitle
{
    if ([formData[@"visit_type_id"] isEqualToString:supervisorId]) return;

    [formData setObject:supervisorId forKey:@"supervisor_id"];
    [formData setObject:supervisorTitle forKey:@"supervisorTitle"];
    supervisorCell.detailTextLabel.text = supervisorTitle;
    [self.tableView reloadData]; 
}

Upvotes: 0

Views: 321

Answers (1)

Martin R
Martin R

Reputation: 539955

NSNull * is incompatible to NSString *. But you can call

[self.delegate setSupervisorGUID:nil supervisorTitle:@"User not set"];

instead and check for supervisorId == nil in the delegate method.

Upvotes: 1

Related Questions