Files
leanote-ios/Leanote/view/NSString+Util.m
lealife 819cb19506 Remove WordPress-iOS-Shared WordPressCom-Analytics-iOS
Update AFNetworking to 4.0
NSURLProtocol+WebKitSupport.h for WKWebView https://github.com/Yeatse/NSURLProtocol-WebKitSupport
2020-04-24 17:01:50 +08:00

33 lines
821 B
Objective-C

#import "NSString+Util.h"
@implementation NSString (Util)
- (bool)isEmpty {
return self.length == 0;
}
- (NSString *)trim {
NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet];
return [self stringByTrimmingCharactersInSet:set];
}
- (NSNumber *)numericValue {
return [NSNumber numberWithUnsignedLongLong:[self longLongValue]];
}
- (CGSize)suggestedSizeWithFont:(UIFont *)font width:(CGFloat)width {
CGRect bounds = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: font} context:nil];
return bounds.size;
}
@end
@implementation NSObject (NumericValueHack)
- (NSNumber *)numericValue {
if ([self isKindOfClass:[NSNumber class]]) {
return (NSNumber *)self;
}
return nil;
}
@end