-
Notifications
You must be signed in to change notification settings - Fork 0
/
SWControlValueAdditions.m
50 lines (39 loc) · 1.12 KB
/
SWControlValueAdditions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// SWControlNumberValue.m
// This file is part of the "SWApplicationSupport" project, and is distributed under the MIT License.
//
// Created by Samuel Williams on 21/07/06.
// Copyright 2006 Samuel Williams. All rights reserved.
//
#import "SWControlValueAdditions.h"
@implementation NSControl (SWControlNumberValue)
- (NSNumber*)numberValue {
if (self.formatter)
return [self.formatter numberFromString:self.stringValue];
else
return nil;
}
- (NSDecimalNumber*)decimalNumberValue {
if (self.formatter)
return [NSDecimalNumber decimalNumberWithDecimal:self.numberValue.decimalValue];
else
return [NSDecimalNumber decimalNumberWithString:self.stringValue];
}
- (void) setNumberValue: (NSNumber*)number {
if (self.formatter)
self.stringValue = [self.formatter stringFromNumber:number];
else// if ([number isKindOfClass:[NSDecimalNumber class]])
self.stringValue = ((NSDecimalNumber*)number).description;
}
@end
@implementation NSButton (SWControlBoolValue)
- (BOOL) boolValue {
if (self.state == NSOnState)
return YES;
else
return NO;
}
- (NSNumber*) boolNumberValue {
return @(self.boolValue);
}
@end