Repository: realm/realm-swift
File: tools/RealmBrowser/RealmBrowser/Classes/RLMInstanceTableViewController.m (Objective-C)

Code before:
    }
}

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
    if (tableView != self.tableView) {
        return nil;
    }
    
    NSUInteger columnIndex = [tableView.tableColumns indexOfObject:tableColumn];
    RLMTypeNode *displayedType = self.displayedType;
    
    RLMClassProperty *classProperty = displayedType.propertyColumns[columnIndex];
    RLMObject *selectedInstance = [displayedType instanceAtIndex:rowIndex];
    id propertyValue = selectedInstance[classProperty.name];
    RLMPropertyType type = classProperty.type;

    NSTableCellView *cellView;
    
    switch (classProperty.type) {
        case RLMPropertyTypeArray: {
            RLMBadgeTableCellView *badgeCellView = [tableView makeViewWithIdentifier:@"BadgeCell" owner:self];
            
            badgeCellView.badge.hidden = NO;
            badgeCellView.badge.title = [NSString stringWithFormat:@"%lu", [(RLMArray *)propertyValue count]];
            [badgeCellView.badge.cell setHighlightsBy:0];
            
            NSString *formattedText = [self printablePropertyValue:propertyValue ofType:type];
            
            badgeCellView.textField.stringValue = formattedText;
            badgeCellView.textField.font = [NSFont linkFont];
            
            [badgeCellView.textField setEditable:NO];
            
            cellView = badgeCellView;
        }
            break;
            
        case RLMPropertyTypeBool: {
            RLMBoolTableCellView *boolCellView = [tableView makeViewWithIdentifier:@"BoolCell" owner:self];
            
            boolCellView.checkBox.state = [(NSNumber *)propertyValue boolValue] ? NSOnState : NSOffState;
            [boolCellView.checkBox setEnabled:!self.realmIsLocked];
            
            cellView = boolCellView;
        }
            break;
            
        case RLMPropertyTypeInt:
        case RLMPropertyTypeFloat:
        case RLMPropertyTypeDouble: {

Review comment (suggestion):
In this case the reason for it to be -1 is not that it wasn't found, but rather because in array display mode everything is shifted because of the index column. So I'm not sure it makes sense in this case, but I will make sure that we use it when it results from a comparison.


Code after:
    return [tableColumn sizeThatFitsWithLimit:NO];
}

- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
    if (self.tableView == notification.object) {
        NSInteger selectedIndex = self.tableView.selectedRow;
        
        [self.parentWindowController.currentState updateSelectionToIndex:selectedIndex];
    }
}

-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
{
    if (tableView != self.tableView) {
        return nil;
    }
    
    NSUInteger columnIndex = [tableView.tableColumns indexOfObject:tableColumn];
    RLMTypeNode *displayedType = self.displayedType;

    if ([displayedType isMemberOfClass:[RLMArrayNode class]]) {
        columnIndex--;
    }
    
    if (columnIndex == -1) {
        RLMBasicTableCellView *basicCellView = [tableView makeViewWithIdentifier:@"BasicCell" owner:self];
        basicCellView.textField.stringValue = [@(rowIndex) stringValue];
        
        return basicCellView;
    }

    RLMClassProperty *classProperty = displayedType.propertyColumns[columnIndex];
    RLMObject *selectedInstance = [displayedType instanceAtIndex:rowIndex];
    id propertyValue = selectedInstance[classProperty.name];
    RLMPropertyType type = classProperty.type;

    NSTableCellView *cellView;
    
    switch (classProperty.type) {
        case RLMPropertyTypeArray: {
            RLMBadgeTableCellView *badgeCellView = [tableView makeViewWithIdentifier:@"BadgeCell" owner:self];
            
            badgeCellView.badge.hidden = NO;
            badgeCellView.badge.title = [NSString stringWithFormat:@"%lu", [(RLMArray *)propertyValue count]];
            [badgeCellView.badge.cell setHighlightsBy:0];
            
            NSString *formattedText = [self printablePropertyValue:propertyValue ofType:type];
            
            badgeCellView.textField.stringValue = formattedText;
            badgeCellView.textField.font = [NSFont linkFont];