NSFormatter problem: not getting called for the empty string

Posted by Enchilada on Stack Overflow See other posts from Stack Overflow or by Enchilada
Published on 2011-01-04T00:48:35Z Indexed on 2011/01/04 0:54 UTC
Read the original article Hit count: 284

Filed under:
|

I have created a custom formatter for my (read-only) table column. It looks like this:

- (NSString *)stringForObjectValue:(id)anObject
{ 
  NSAssert([anObject isKindOfClass:[NSString class]] && anObject != nil,
            @"invalid object");

  if ([anObject isEqualToString:@""])
    return @"EMPTY";
  else
    return [anObject stringByAppendingString:@"++"];
}

Very simple. The corresponding objects are just strings, so it's an string-to-string formatter. All non-empty string objects are returned with @"++" appended to them. Empty string objects should be turned into the @"EMPTY" string.

The @"++" gets appended to non-empty strings just fine.

The problem is, @"EMPTY" never gets shown! My formatter is never called by Cocoa when the underlying object is the empty string. The corresponding row just keeps being empty, instead of showing my requested @"EMPTY".

Any ideas?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa