Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 NSKeyedArchiver warning: replacing existing value for key 'UITintColor'; probable duplication of encoding keys in class hierarchy

I have created a uitableviewcell using a xib. And I have a cell factory where the cell is unarchived this way:

- (instancetype)initWithNib:(NSString *)aNibName
{
    self = [super init];    
    if (self != nil) {

        self.viewTemplateStore = [[NSMutableDictionary alloc] init];
        NSArray * templates = [[NSBundle mainBundle] loadNibNamed:aNibName owner:self options:nil];

        for (id template in templates) {
            if ([template isKindOfClass:[UITableViewCell class]]) {                
                UITableViewCell * cellTemplate = (UITableViewCell *)template;
                NSString * key = cellTemplate.reuseIdentifier;

                if (key) {
                    [self.viewTemplateStore setObject:[NSKeyedArchiver archivedDataWithRootObject:template] forKey:key];
                } else {
                    @throw [NSException exceptionWithName:@"Unknown cell"
                                                   reason:@"Cell has no reuseIdentifier"
                                                 userInfo:nil];
                }
            }
        }
    }
    return self;
}

- (UITableViewCell *)cellOfKind:(NSString *)theCellKind forTable:(UITableView *)aTableView
{
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:theCellKind];

    if (!cell) {
        NSData * cellData = [self.viewTemplateStore objectForKey:theCellKind];

        if (cellData) {
            cell = [NSKeyedUnarchiver unarchiveObjectWithData:cellData];
        } else {
            DDLogError(@"Don't know nothing about cell of kind %@", theCellKind);
        }
    }
    return cell;
}

If UIActivityIndicatorView is added to the cell then this message appears in the console:

* NSKeyedArchiver warning: replacing existing value for key 'UITintColor'; probable duplication of encoding keys in class hierarchy

It only happens in iOS7. The UIActivityIndicatorView has the default values, I just drag and drop it on to the cell.

Any clue about why this message appears?

Thanks.

like image 264
LightMan Avatar asked Nov 11 '22 14:11

LightMan


1 Answers

This is a bug introduced in iOS7.

You are calling [NSKeyedArchiver archivedDataWithRootObject:template], which is causing the whole view hierarchy to be archived (using the procedure encodeWithCoder:).

The problem causing the warning is that UIActivityIndicatorView is the subclass of UIView, which also conforms <NSCoding> protocol. Prior to iOS7, views like Navigation Bar, Activity Indicator and others had their Tint property, but in iOS7 the Tint property is present in the UIView itself. So both the UIViewActivityIndicator and its ancestor UIView are encoding this Tint property for UITintColor key, first it's set by UIView and then overwritten by UIActivityIndicatorView. That's why this warning is appearing. No need to worry about it.

BTW, why are you using so strange code to generate cells? You may register all the reuseIdentifiers to appropriate Nib in viewDidLoad:

[self.tableView registerNib:[UINib nibWithNibName:@"Cells" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell1"];

and then the tableView itself will load a cell when you call

[tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
like image 135
Alexey Martemyanov Avatar answered Nov 15 '22 04:11

Alexey Martemyanov