Skip to content

Commit a4ab19d

Browse files
authored
Merge pull request #721 from kinarobin/fix_number_formatter_transform_bug
Fix number formatter transform bug
2 parents 52c53d6 + 7239ec5 commit a4ab19d

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

MJExtension/NSObject+MJKeyValue.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ + (BOOL)mj_isReferenceReplacedKeyWhenCreatingKeyValues
5353
}
5454

5555
#pragma mark - --常用的对象--
56-
static NSNumberFormatter *numberFormatter_;
5756
+ (void)load
5857
{
59-
numberFormatter_ = [[NSNumberFormatter alloc] init];
60-
6158
// 默认设置
6259
[self mj_referenceReplacedKeyWhenCreatingKeyValues:YES];
6360
}
@@ -162,7 +159,7 @@ - (instancetype)mj_setKeyValues:(id)keyValues context:(NSManagedObjectContext *)
162159
if (type.typeClass == [NSDecimalNumber class]) {
163160
value = [NSDecimalNumber decimalNumberWithString:oldValue];
164161
} else {
165-
value = [numberFormatter_ numberFromString:oldValue];
162+
value = @([NSDecimalNumber decimalNumberWithString:oldValue].doubleValue);
166163
}
167164

168165
// 如果是BOOL

MJExtensionDemo.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@
627627
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
628628
CODE_SIGN_STYLE = Automatic;
629629
INFOPLIST_FILE = MJExtensionDemo/Info.plist;
630+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
630631
LD_RUNPATH_SEARCH_PATHS = (
631632
"$(inherited)",
632633
"@executable_path/Frameworks",
@@ -643,6 +644,7 @@
643644
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
644645
CODE_SIGN_STYLE = Automatic;
645646
INFOPLIST_FILE = MJExtensionDemo/Info.plist;
647+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
646648
LD_RUNPATH_SEARCH_PATHS = (
647649
"$(inherited)",
648650
"@executable_path/Frameworks",

MJExtensionTests/MJExtensionTests.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ - (void)testJSON2Model {
3434
@"height" : @1.55,
3535
@"money" : @"100.9",
3636
@"sex" : @(SexFemale),
37-
@"gay" : @"1"
37+
@"gay" : @"1",
38+
@"speed" : @"120.5",
39+
@"identifier" : @"3443623624362",
40+
@"price" : @"20.3",
3841
// @"gay" : @"NO"
3942
// @"gay" : @"true"
4043
};
@@ -50,6 +53,9 @@ - (void)testJSON2Model {
5053
XCTAssert(user.money.doubleValue == 100.9);
5154
XCTAssert(user.sex == SexFemale);
5255
XCTAssert(user.gay == YES);
56+
XCTAssert(user.speed == 120);
57+
XCTAssert(user.identifier == 3443623624362);
58+
XCTAssert(user.price == 20.3);
5359
}
5460

5561
#pragma mark JSON字符串 -> 模型

MJExtensionTests/Model/MJUser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@ typedef enum {
2828
@property (assign, nonatomic) Sex sex;
2929
/** 同性恋 */
3030
@property (assign, nonatomic, getter=isGay) BOOL gay;
31+
/** 速度 */
32+
@property (assign, nonatomic) NSInteger speed;
33+
/** 标识 */
34+
@property (assign, nonatomic) long long identifier;
35+
/** 价格 */
36+
@property (assign, nonatomic) double price;
37+
3138
@end

0 commit comments

Comments
 (0)