mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-22 16:29:23 +00:00
Using custom NSNumberFormatter to prevent errors on validation.
This commit is contained in:
33
MacPass/MPNumberFormatter.m
Normal file
33
MacPass/MPNumberFormatter.m
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// MPNumberFormatter.m
|
||||
// MacPass
|
||||
//
|
||||
// Created by Michael Starke on 24/08/16.
|
||||
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPNumberFormatter.h"
|
||||
|
||||
@implementation MPNumberFormatter
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
|
||||
self = [super initWithCoder:aDecoder];
|
||||
self.minimum = [NSDecimalNumber one];
|
||||
self.formatterBehavior = NSNumberFormatterBehavior10_4;
|
||||
self.allowsFloats = NO;
|
||||
self.alwaysShowsDecimalSeparator = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(out id __nullable * __nullable)obj forString:(NSString *)string errorDescription:(out NSString * __nullable * __nullable)error {
|
||||
/* If super can pase without an error, all is fine */
|
||||
if([super getObjectValue:obj forString:string errorDescription:error]) {
|
||||
return YES;
|
||||
}
|
||||
/* TODO adhere to minimum/maxiumum? */
|
||||
*obj = [self.minimum copy];
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user