Skip to content

Commit

Permalink
Swizzled NSString numeric methods like -doubleValue, -boolValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ElfSundae committed May 29, 2019
1 parent 800fc30 commit e7ac4b1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Rename UIView `-findSuperviewOf:` => `-findSuperviewOfClass:`, `-findSubviewOf:` => `-findSubviewOfClass:`.
- Added missing numeric methods for NSString: `-charValue`, `-longValue`, etc.
- Swizzled NSString numeric methods like `-doubleValue`, `-boolValue`.
- Added `ESCharValue(id)`, `ESUCharValue(id)`, `ESShortValue(id)`, `ESUShortValue(id)`.

## 3.4.1 (2019-05-28)
Expand Down
44 changes: 44 additions & 0 deletions ESFramework/Foundation/NSString+ESAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,56 @@
//

#import "NSString+ESAdditions.h"
#import "ESHelpers.h"
#import "NSNumber+ESAdditions.h"
#import "NSCharacterSet+ESAdditions.h"
#import "NSURLComponents+ESAdditions.h"

@implementation NSString (ESAdditions)

+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
ESSwizzleInstanceMethod(self, @selector(doubleValue), @selector(es_doubleValue));
ESSwizzleInstanceMethod(self, @selector(floatValue), @selector(es_floatValue));
ESSwizzleInstanceMethod(self, @selector(intValue), @selector(es_intValue));
ESSwizzleInstanceMethod(self, @selector(integerValue), @selector(es_integerValue));
ESSwizzleInstanceMethod(self, @selector(longLongValue), @selector(es_longLongValue));
ESSwizzleInstanceMethod(self, @selector(boolValue), @selector(es_boolValue));
});
}

- (double)es_doubleValue
{
return self.numberValue.doubleValue;
}

- (float)es_floatValue
{
return self.numberValue.floatValue;
}

- (int)es_intValue
{
return self.numberValue.intValue;
}

- (NSInteger)es_integerValue
{
return self.numberValue.integerValue;
}

- (long long)es_longLongValue
{
return self.numberValue.longLongValue;
}

- (BOOL)es_boolValue
{
return self.numberValue.boolValue;
}

- (NSNumber *)numberValue
{
return [NSNumber numberWithString:self];
Expand Down

0 comments on commit e7ac4b1

Please sign in to comment.