Skip to content

Commit 1af49c9

Browse files
authored
Merge pull request #4 from kbonana/feature/Optimization
Feature/optimization
2 parents 1380453 + 46b8fd2 commit 1af49c9

File tree

15 files changed

+223
-138
lines changed

15 files changed

+223
-138
lines changed

Examples/iOSExample/iOSExample.xcodeproj/project.pbxproj

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
/* Begin PBXBuildFile section */
1010
2446FAE51E7B2DFD00E46A7D /* WBUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 2446FAE41E7B2DFD00E46A7D /* WBUser.m */; };
11+
248F29531EBDBEC70029852E /* SimpleModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 248F29521EBDBEC70029852E /* SimpleModel.m */; };
12+
248F29541EBDBFD60029852E /* simple.json in Resources */ = {isa = PBXBuildFile; fileRef = 248F294F1EBDBE8E0029852E /* simple.json */; };
13+
248F29551EBDD5450029852E /* SimpleModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 248F29521EBDBEC70029852E /* SimpleModel.m */; };
1114
24D296111E7E806500F84C23 /* JSObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D296101E7E806500F84C23 /* JSObject.m */; };
1215
6445C3E9A768C6844103543B /* libPods-iOSExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 20A1D98A497DDD701351126F /* libPods-iOSExample.a */; };
1316
774DF4E81E0D04C300621AC7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 774DF4D21E0D04C300621AC7 /* Info.plist */; };
@@ -76,6 +79,9 @@
7679
2446FAE31E7B2DFD00E46A7D /* WBUser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBUser.h; sourceTree = "<group>"; };
7780
2446FAE41E7B2DFD00E46A7D /* WBUser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBUser.m; sourceTree = "<group>"; };
7881
2446FAE61E7B2E9E00E46A7D /* PrefixHeader.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrefixHeader.pch; sourceTree = "<group>"; };
82+
248F294F1EBDBE8E0029852E /* simple.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = simple.json; sourceTree = "<group>"; };
83+
248F29511EBDBEC70029852E /* SimpleModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleModel.h; sourceTree = "<group>"; };
84+
248F29521EBDBEC70029852E /* SimpleModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SimpleModel.m; sourceTree = "<group>"; };
7985
24D2960F1E7E806500F84C23 /* JSObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSObject.h; sourceTree = "<group>"; };
8086
24D296101E7E806500F84C23 /* JSObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSObject.m; sourceTree = "<group>"; };
8187
774DF4D21E0D04C300621AC7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -365,8 +371,11 @@
365371
A9F9A0271E08B06D00E22FE7 /* iOSExampleTests */ = {
366372
isa = PBXGroup;
367373
children = (
374+
248F294F1EBDBE8E0029852E /* simple.json */,
368375
A9F9A0281E08B06D00E22FE7 /* iOSExampleTests.m */,
369376
A9F9A02A1E08B06D00E22FE7 /* Info.plist */,
377+
248F29511EBDBEC70029852E /* SimpleModel.h */,
378+
248F29521EBDBEC70029852E /* SimpleModel.m */,
370379
);
371380
path = iOSExampleTests;
372381
sourceTree = "<group>";
@@ -485,6 +494,7 @@
485494
A9F9A01B1E08B06C00E22FE7 /* Assets.xcassets in Resources */,
486495
EF4EE01B1E5DCB6100E4565A /* ProfileTableViewCell.xib in Resources */,
487496
77756B441E0DF052006F5938 /* public_timeline.json in Resources */,
497+
248F29541EBDBFD60029852E /* simple.json in Resources */,
488498
A9F9A0191E08B06C00E22FE7 /* Main.storyboard in Resources */,
489499
774DF4E81E0D04C300621AC7 /* Info.plist in Resources */,
490500
);
@@ -569,6 +579,7 @@
569579
24D296111E7E806500F84C23 /* JSObject.m in Sources */,
570580
A9F9A0361E08B1C800E22FE7 /* HomeTimelineController.m in Sources */,
571581
774DF4EE1E0D04C300621AC7 /* NSObject+MJClass.m in Sources */,
582+
248F29551EBDD5450029852E /* SimpleModel.m in Sources */,
572583
77756B421E0D6523006F5938 /* NSMutableDictionary+JSONCore.m in Sources */,
573584
A92AA9501E08D24E00B4579F /* WeiboViewModel.m in Sources */,
574585
A92AA96F1E08E38B00B4579F /* JSONCoreProperty.m in Sources */,
@@ -589,6 +600,7 @@
589600
buildActionMask = 2147483647;
590601
files = (
591602
A9F9A0291E08B06D00E22FE7 /* iOSExampleTests.m in Sources */,
603+
248F29531EBDBEC70029852E /* SimpleModel.m in Sources */,
592604
);
593605
runOnlyForDeploymentPostprocessing = 0;
594606
};
@@ -663,7 +675,7 @@
663675
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
664676
GCC_WARN_UNUSED_FUNCTION = YES;
665677
GCC_WARN_UNUSED_VARIABLE = YES;
666-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
678+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
667679
MTL_ENABLE_DEBUG_INFO = YES;
668680
ONLY_ACTIVE_ARCH = YES;
669681
SDKROOT = iphoneos;
@@ -706,7 +718,7 @@
706718
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
707719
GCC_WARN_UNUSED_FUNCTION = YES;
708720
GCC_WARN_UNUSED_VARIABLE = YES;
709-
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
721+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
710722
MTL_ENABLE_DEBUG_INFO = NO;
711723
SDKROOT = iphoneos;
712724
TARGETED_DEVICE_FAMILY = "1,2";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>classNames</key>
6+
<dict>
7+
<key>iOSExampleTests</key>
8+
<dict>
9+
<key>testPerformanceExample</key>
10+
<dict>
11+
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
12+
<dict>
13+
<key>baselineAverage</key>
14+
<real>0.33</real>
15+
<key>baselineIntegrationDisplayName</key>
16+
<string>Local Baseline</string>
17+
</dict>
18+
</dict>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>runDestinationsByUUID</key>
6+
<dict>
7+
<key>49388E3E-0B7E-40FB-B2A6-2C319C384E39</key>
8+
<dict>
9+
<key>localComputer</key>
10+
<dict>
11+
<key>busSpeedInMHz</key>
12+
<integer>100</integer>
13+
<key>cpuCount</key>
14+
<integer>1</integer>
15+
<key>cpuKind</key>
16+
<string>Intel Core i7</string>
17+
<key>cpuSpeedInMHz</key>
18+
<integer>4009</integer>
19+
<key>logicalCPUCoresPerPackage</key>
20+
<integer>8</integer>
21+
<key>modelCode</key>
22+
<string>iMac14,2</string>
23+
<key>physicalCPUCoresPerPackage</key>
24+
<integer>4</integer>
25+
<key>platformIdentifier</key>
26+
<string>com.apple.platform.macosx</string>
27+
</dict>
28+
<key>targetArchitecture</key>
29+
<string>x86_64</string>
30+
<key>targetDevice</key>
31+
<dict>
32+
<key>modelCode</key>
33+
<string>iPhone8,1</string>
34+
<key>platformIdentifier</key>
35+
<string>com.apple.platform.iphonesimulator</string>
36+
</dict>
37+
</dict>
38+
</dict>
39+
</dict>
40+
</plist>

Examples/iOSExample/iOSExample/AppDelegate.m

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import "AppDelegate.h"
1010
#import "WeiboSDK.h"
11+
#import "SimpleModel.h"
1112

1213
@interface AppDelegate () <WeiboSDKDelegate>
1314

@@ -22,6 +23,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2223
LogInfo(@"提示信息");
2324
LogWarn(@"警告信息");
2425
LogError(@"错误信息");
26+
27+
/*NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"simple.json" ofType:nil]];
28+
29+
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
30+
NSArray *arr = [SimpleModel arrayOfModelsFromDictionaries:jsonArray];*/
2531
return YES;
2632
}
2733

Examples/iOSExample/iOSExample/Weibo/WeiboModel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
*/
2222
+ (instancetype)jsonObjectFromData:(id)data;
23-
+ (NSArray *)arrayOfModelsFromDictionaries:(NSArray *)array;
23+
+ (NSArray *)arrayOfModelsFromKeyValues:(id)keyValues;
2424

2525
/**
2626
允许的属性名

Examples/iOSExample/iOSExample/Weibo/WeiboModel.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ + (instancetype)jsonObjectFromData:(id)data {
2323
return [self co_objectFromKeyValues:data];
2424
}
2525

26-
+ (NSArray *)arrayOfModelsFromDictionaries:(NSArray *)array {
27-
return [self co_arrayOfModelsFromDictionaries:array];
26+
+ (NSArray *)arrayOfModelsFromKeyValues:(id)keyValues {
27+
return [self co_arrayOfModelsFromKeyValues:keyValues];
2828
}
2929

3030
+ (NSArray *)allowedPropertyNames {

Examples/iOSExample/iOSExample/Weibo/WeiboViewModel.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ - (BOOL)ssoAuthorizeRequest {
4343
- (void)requestFriendsTimeline:(void (^)())completion {
4444
[WeiboRequest startRequestWithURL:@"https://api.weibo.com/2/statuses/friends_timeline.json" completion:^(id obj) {
4545
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:obj options:NSJSONReadingMutableContainers error:nil];
46-
self.statuses = [StatuseModel arrayOfModelsFromDictionaries:dict[@"statuses"]];
46+
self.statuses = [StatuseModel arrayOfModelsFromKeyValues:dict[@"statuses"]];
4747
LogInfo(@"%@",self.statuses.firstObject.toJSONString);
4848
if (completion) {
4949
completion();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// SimpleModel.h
3+
// iOSExample
4+
//
5+
// Created by bonana on 2017/5/6.
6+
// Copyright © 2017年 maintoco. All rights reserved.
7+
//
8+
9+
#import "WeiboModel.h"
10+
11+
@interface SimpleModel : WeiboModel
12+
13+
@property (nonatomic, assign) bool boolValue; //TB
14+
@property (nonatomic, assign) char charValue; //Tc
15+
@property (nonatomic, assign) unsigned char unsignedCharValue; //TC
16+
@property (nonatomic, assign) short shortValue; //Ts
17+
@property (nonatomic, assign) unsigned short unsignedShortValue; //TS
18+
@property (nonatomic, assign) int intValue; //Ti
19+
@property (nonatomic, assign) unsigned int unsignedIntValue; //TI
20+
@property (nonatomic, assign) long longValue; //Tl
21+
@property (nonatomic, assign) unsigned long unsignedLongValue; //TL
22+
@property (nonatomic, assign) long long longLongValue; //Tq
23+
@property (nonatomic, assign) unsigned long long unsignedLongLongValue; //TQ
24+
@property (nonatomic, assign) float floatValue; //Tf
25+
@property (nonatomic, assign) double doubleValue; //Td
26+
@property (nonatomic, assign) long double longdbValue; //Td (Objective-C does not support the long double type. @encode(long double) returns d, which is the same encoding as for double.)
27+
28+
@property (nonatomic, strong) NSNumber *number;
29+
@property (nonatomic, strong) NSDate *date;
30+
@property (nonatomic, copy) NSString *string;
31+
@property (nonatomic, strong) NSDictionary *dict;
32+
@property (nonatomic, strong) NSArray<SimpleModel *> *simpleArray;
33+
@property (nonatomic, strong) SimpleModel *nestObj;
34+
35+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SimpleModel.m
3+
// iOSExample
4+
//
5+
// Created by bonana on 2017/5/6.
6+
// Copyright © 2017年 maintoco. All rights reserved.
7+
//
8+
9+
#import "SimpleModel.h"
10+
11+
@implementation SimpleModel
12+
13+
@end

Examples/iOSExample/iOSExampleTests/iOSExampleTests.m

+7-45
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "StatuseModel.h"
11-
12-
@interface PodModel : NSObject
13-
@property (nonatomic, assign) int tag;
14-
@property (nonatomic, retain) NSMutableArray *phoneNums;
15-
16-
@end
17-
18-
@implementation PodModel
19-
20-
@end
11+
#import "SimpleModel.h"
12+
#import "NSObject+MJKeyValue.h"
2113

2214
@interface iOSExampleTests : XCTestCase
2315

@@ -39,48 +31,18 @@ - (void)testExample {
3931
// This is an example of a functional test case.
4032
// Use XCTAssert and related functions to verify your tests produce the correct results.
4133

42-
NSMutableArray *rarr = [@[@"01",@"02",@"03",@"04",@"05",@"06"] mutableCopy];
43-
NSMutableArray *podArr = [NSMutableArray array];
44-
for (int i=0; i<10; i++) {
45-
PodModel *model = [PodModel new];
46-
model.tag = i;
47-
model.phoneNums = [NSMutableArray array];
48-
for (int j=0; j<i; j++) {
49-
[model.phoneNums addObject:[NSString stringWithFormat:@"%02d",j]];
50-
}
51-
[podArr addObject:model];
52-
}
53-
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K in %@",@"phoneNums",rarr];
54-
NSExpression *left = [NSExpression expressionForKeyPath:@"phoneNums"];
55-
NSExpression *right = [NSExpression expressionForConstantValue:rarr];
56-
57-
NSComparisonPredicate *compPredicate = [NSComparisonPredicate predicateWithLeftExpression:left rightExpression:right modifier:NSDirectPredicateModifier type:NSInPredicateOperatorType options:0];
58-
59-
NSArray *filteredArr = [podArr filteredArrayUsingPredicate:compPredicate];
60-
if (filteredArr.count > 0) {
61-
NSLog(@"%d",0);
62-
}
63-
64-
// for (PodModel *obj in podArr) {
65-
// NSArray *filteredArr = [obj.phoneNums filteredArrayUsingPredicate:predicate];
66-
// if (filteredArr.count > 0) {
67-
// NSLog(@"%d",obj.tag);
68-
// }
69-
// }
34+
NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"simple.json" ofType:nil]];
35+
NSArray *arr = [SimpleModel arrayOfModelsFromKeyValues:jsonData];
36+
NSLog(@"%@",arr);
7037
}
7138

7239
- (void)testPerformanceExample {
7340
// This is an example of a performance test case.
7441
NSData *jsonData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"public_timeline.json" ofType:nil]];
75-
NSArray *arr = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
76-
__block int count;
7742
[self measureBlock:^{
7843
for (int i=0; i<100; i++) {
79-
NSArray *result = [StatuseModel arrayOfModelsFromDictionaries:arr];
80-
count++;
81-
}
82-
if (count == 1000) {
83-
NSLog(@"%d",count);
44+
NSArray *result = [StatuseModel arrayOfModelsFromKeyValues:jsonData];
45+
//NSArray *result = [StatuseModel mj_objectArrayWithKeyValuesArray:jsonData];
8446
}
8547
}];
8648
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"boolValue": 1,
4+
"charValue": 65,
5+
"unsignedCharValue": -191,
6+
"shortValue": 60000,
7+
"unsignedShortValue": -30000,
8+
"intValue": 10000,
9+
"unsignedIntValue": 10000,
10+
"longValue": 54321.96,
11+
"unsignedLongValue": 54321,
12+
"longLongValue": 54321.6,
13+
"unsignedLongLongValue": 54321.9,
14+
"floatValue": 1358.0123456789,
15+
"doubleValue": 13889.0123456789,
16+
"longdbValue":54321.0123456789,
17+
"nestObj" : {}
18+
}
19+
]

JSONCore.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Pod::Spec.new do |s|
88
s.license = "MIT"
99
s.author = { "bonana" => "[email protected]" }
1010
s.social_media_url = "http://weibo.com/fenglaijun"
11-
s.source = { :git => "https://github.com/kbonana/JSONCore.git", :tag => s.version }
11+
s.source = { :git => "https://github.com/kbonana/JSONCore.git" }
1212
s.source_files = "JSONCore"
1313
s.requires_arc = true
1414
end

0 commit comments

Comments
 (0)