Created
August 2, 2011 07:39
-
-
Save iburlakov/1119762 to your computer and use it in GitHub Desktop.
Simple implementation of NSFormatter class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface LimitFormatter : NSFormatter { | |
} | |
@property int maxLength; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "LimitFormatter.h" | |
@implementation LimitFormatter : NSFormatter | |
@synthesize maxLength; | |
- (id)init { | |
if([super init]){ | |
maxLength = INT_MAX; | |
} | |
return self; | |
} | |
- (NSString *)stringForObjectValue:(id)object { | |
return (NSString *)object; | |
} | |
- (BOOL)getObjectValue:(id *)object | |
forString:(NSString *)string | |
errorDescription:(NSString **)error { | |
*object = string; | |
return YES; | |
} | |
-(BOOL)isPartialStringValid:(NSString *)partialString | |
newEditingString:(NSString **)newString | |
errorDescription:(NSString **)error{ | |
if([partialString length] > maxLength){ | |
return NO; | |
} | |
return YES; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple implementation of NSFormatter class, just set maximum character's limit that user can enter into NSTextField.