title: Set limit to NSTextField
body: <p>I need to set a character limit for TextFields. I followed this <a href="https://stackoverflow.com/a/830019/913571">answer</a> and I was able to set a limit. But now when I press enter all characters are wiped out. What went wrong ?</p>
  
  <pre><code>- (BOOL)isPartialStringValid:(NSString *__autoreleasing *)partialStringPtr
         proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
                originalString:(NSString *)origString
         originalSelectedRange:(NSRange)origSelRange
              errorDescription:(NSString *__autoreleasing *)error {
      if ([*partialStringPtr length] &gt; maxLength)
          return NO;
      else
          return YES;
  }
  
  - (NSString *)stringForObjectValue:(id)obj {
      return (NSString*) obj;
  }
  
  - (BOOL)getObjectValue:(out __autoreleasing id *)obj
               forString:(NSString *)string
        errorDescription:(out NSString *__autoreleasing *)error {
      return YES;
  }
  
  - (NSAttributedString *)attributedStringForObjectValue:(id)obj
                                   withDefaultAttributes:(NSDictionary *)attrs {
      return (NSAttributedString*) obj;
  }
  </code></pre>