新建了BaseObject 模型的基类 以及模型相互转换的方法
This commit is contained in:
3
Podfile
3
Podfile
@@ -8,11 +8,12 @@ target 'xplan-ios' do
|
|||||||
# Pods for xplan-ios
|
# Pods for xplan-ios
|
||||||
pod 'AFNetworking'
|
pod 'AFNetworking'
|
||||||
pod 'YYText'
|
pod 'YYText'
|
||||||
pod 'YYModel'
|
|
||||||
pod 'Masonry'
|
pod 'Masonry'
|
||||||
pod 'ReactiveObjC'
|
pod 'ReactiveObjC'
|
||||||
pod 'MBProgressHUD'
|
pod 'MBProgressHUD'
|
||||||
#易盾 本机一键登录
|
#易盾 本机一键登录
|
||||||
pod 'NTESQuickPass', '~> 2.1.6'
|
pod 'NTESQuickPass', '~> 2.1.6'
|
||||||
|
#模型转化
|
||||||
|
pod 'MJExtension'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
12
Podfile.lock
12
Podfile.lock
@@ -16,18 +16,18 @@ PODS:
|
|||||||
- AFNetworking/NSURLSession
|
- AFNetworking/NSURLSession
|
||||||
- Masonry (1.1.0)
|
- Masonry (1.1.0)
|
||||||
- MBProgressHUD (1.2.0)
|
- MBProgressHUD (1.2.0)
|
||||||
|
- MJExtension (3.3.0)
|
||||||
- NTESQuickPass (2.1.9)
|
- NTESQuickPass (2.1.9)
|
||||||
- ReactiveObjC (3.1.1)
|
- ReactiveObjC (3.1.1)
|
||||||
- YYModel (1.0.4)
|
|
||||||
- YYText (1.0.7)
|
- YYText (1.0.7)
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- AFNetworking
|
- AFNetworking
|
||||||
- Masonry
|
- Masonry
|
||||||
- MBProgressHUD
|
- MBProgressHUD
|
||||||
|
- MJExtension
|
||||||
- NTESQuickPass (~> 2.1.6)
|
- NTESQuickPass (~> 2.1.6)
|
||||||
- ReactiveObjC
|
- ReactiveObjC
|
||||||
- YYModel
|
|
||||||
- YYText
|
- YYText
|
||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
@@ -35,20 +35,20 @@ SPEC REPOS:
|
|||||||
- AFNetworking
|
- AFNetworking
|
||||||
- Masonry
|
- Masonry
|
||||||
- MBProgressHUD
|
- MBProgressHUD
|
||||||
|
- MJExtension
|
||||||
- NTESQuickPass
|
- NTESQuickPass
|
||||||
- ReactiveObjC
|
- ReactiveObjC
|
||||||
- YYModel
|
|
||||||
- YYText
|
- YYText
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
|
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
|
||||||
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
|
Masonry: 678fab65091a9290e40e2832a55e7ab731aad201
|
||||||
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
|
MBProgressHUD: 3ee5efcc380f6a79a7cc9b363dd669c5e1ae7406
|
||||||
|
MJExtension: 01704cca2b60a214c10761b6491eab74069d68a9
|
||||||
NTESQuickPass: 8431dc52737c95883cd382c2ee75664d58f39377
|
NTESQuickPass: 8431dc52737c95883cd382c2ee75664d58f39377
|
||||||
ReactiveObjC: 011caa393aa0383245f2dcf9bf02e86b80b36040
|
ReactiveObjC: 011caa393aa0383245f2dcf9bf02e86b80b36040
|
||||||
YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
|
|
||||||
YYText: 5c461d709e24d55a182d1441c41dc639a18a4849
|
YYText: 5c461d709e24d55a182d1441c41dc639a18a4849
|
||||||
|
|
||||||
PODFILE CHECKSUM: 34d6fc0f46b543fbcabfb886e7a531f43d5dd7f5
|
PODFILE CHECKSUM: 6662a976a7be0eed298430e68b706dbb92d1ad1e
|
||||||
|
|
||||||
COCOAPODS: 1.10.1
|
COCOAPODS: 1.11.0
|
||||||
|
@@ -56,6 +56,7 @@
|
|||||||
18E7B26926E8D5D60064BC9B /* XCCurrentVCStackManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B26726E8D5D60064BC9B /* XCCurrentVCStackManager.m */; };
|
18E7B26926E8D5D60064BC9B /* XCCurrentVCStackManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18E7B26726E8D5D60064BC9B /* XCCurrentVCStackManager.m */; };
|
||||||
73FFADDC93E195344047A2EC /* Pods_xplan_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF623970097D653132D69A /* Pods_xplan_ios.framework */; };
|
73FFADDC93E195344047A2EC /* Pods_xplan_ios.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CACF623970097D653132D69A /* Pods_xplan_ios.framework */; };
|
||||||
9B0E1C5926E77022005D4442 /* BaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1C5826E77022005D4442 /* BaseNavigationController.m */; };
|
9B0E1C5926E77022005D4442 /* BaseNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9B0E1C5826E77022005D4442 /* BaseNavigationController.m */; };
|
||||||
|
E8B825BA26E9A9D5009E8E9F /* BaseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E8B825B926E9A9D5009E8E9F /* BaseObject.m */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
@@ -157,6 +158,8 @@
|
|||||||
9B0E1C5826E77022005D4442 /* BaseNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
|
9B0E1C5826E77022005D4442 /* BaseNavigationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseNavigationController.m; sourceTree = "<group>"; };
|
||||||
B66633E061B1B34177CD011C /* Pods-xplan-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.release.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.release.xcconfig"; sourceTree = "<group>"; };
|
B66633E061B1B34177CD011C /* Pods-xplan-ios.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-xplan-ios.release.xcconfig"; path = "Target Support Files/Pods-xplan-ios/Pods-xplan-ios.release.xcconfig"; sourceTree = "<group>"; };
|
||||||
CACF623970097D653132D69A /* Pods_xplan_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_xplan_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
CACF623970097D653132D69A /* Pods_xplan_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_xplan_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
E8B825B826E9A9D5009E8E9F /* BaseObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BaseObject.h; sourceTree = "<group>"; };
|
||||||
|
E8B825B926E9A9D5009E8E9F /* BaseObject.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BaseObject.m; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -271,6 +274,8 @@
|
|||||||
187EEEEE26E89FE8002833B2 /* AccountInfoStorage.m */,
|
187EEEEE26E89FE8002833B2 /* AccountInfoStorage.m */,
|
||||||
187EEEFD26E8A82C002833B2 /* NSObject+AutoCoding.h */,
|
187EEEFD26E8A82C002833B2 /* NSObject+AutoCoding.h */,
|
||||||
187EEEFC26E8A82C002833B2 /* NSObject+AutoCoding.m */,
|
187EEEFC26E8A82C002833B2 /* NSObject+AutoCoding.m */,
|
||||||
|
E8B825B826E9A9D5009E8E9F /* BaseObject.h */,
|
||||||
|
E8B825B926E9A9D5009E8E9F /* BaseObject.m */,
|
||||||
);
|
);
|
||||||
path = Model;
|
path = Model;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -619,6 +624,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
189DD76226E60DDC00AB55B1 /* Api+Login.m in Sources */,
|
189DD76226E60DDC00AB55B1 /* Api+Login.m in Sources */,
|
||||||
|
E8B825BA26E9A9D5009E8E9F /* BaseObject.m in Sources */,
|
||||||
18E7B22626E8CDCF0064BC9B /* XplanFlutterBoostDelegate.m in Sources */,
|
18E7B22626E8CDCF0064BC9B /* XplanFlutterBoostDelegate.m in Sources */,
|
||||||
189DD73E26E21C3F00AB55B1 /* YYUtility.m in Sources */,
|
189DD73E26E21C3F00AB55B1 /* YYUtility.m in Sources */,
|
||||||
189DD53426DE255300AB55B1 /* TabbarViewController.m in Sources */,
|
189DD53426DE255300AB55B1 /* TabbarViewController.m in Sources */,
|
||||||
|
@@ -11,7 +11,6 @@
|
|||||||
// Include any system framework and library headers here that should be included in all compilation units.
|
// Include any system framework and library headers here that should be included in all compilation units.
|
||||||
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
|
// You will also need to set the Prefix Header build setting of one or more of your targets to reference this file.
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
#import <YYModel/YYModel.h>
|
|
||||||
|
|
||||||
#define AppName ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])
|
#define AppName ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"])
|
||||||
|
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
// Created by zu on 2021/9/8.
|
// Created by zu on 2021/9/8.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import "BaseObject.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface AccountModel : NSObject<YYModel>
|
@interface AccountModel : BaseObject
|
||||||
|
|
||||||
@property (nonatomic , assign) NSString *uid;
|
@property (nonatomic , assign) NSString *uid;
|
||||||
@property (nonatomic , copy) NSString *jti;
|
@property (nonatomic , copy) NSString *jti;
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
// Created by zu on 2021/9/8.
|
// Created by zu on 2021/9/8.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import "BaseObject.h"
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface BaseModel : NSObject
|
@interface BaseModel : BaseObject
|
||||||
|
|
||||||
@property (nonatomic , strong) id data;
|
@property (nonatomic , strong) id data;
|
||||||
@property (nonatomic , assign) NSInteger code;
|
@property (nonatomic , assign) NSInteger code;
|
||||||
|
35
xplan-ios/Base/MVP/Model/BaseObject.h
Normal file
35
xplan-ios/Base/MVP/Model/BaseObject.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// BaseObject.h
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2021/9/9.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
@interface BaseObject : NSObject
|
||||||
|
/// 依据数组初始化一个实例数组
|
||||||
|
/// @param json json 数据
|
||||||
|
+ (NSArray *)modelsWithArray:(id)json;
|
||||||
|
|
||||||
|
/// 依据字典初始化一个实例
|
||||||
|
/// @param dictionary 字典
|
||||||
|
+ (instancetype)modelWithDictionary:(NSDictionary *)dictionary;
|
||||||
|
|
||||||
|
/// 依据JSON对象初始化一个实例
|
||||||
|
/// @param json json 数据
|
||||||
|
+ (instancetype)modelWithJSON:(id)json;
|
||||||
|
|
||||||
|
///model 转字典
|
||||||
|
- (NSDictionary *)model2dictionary;
|
||||||
|
|
||||||
|
///扩展方法 按需索取 重写即可
|
||||||
|
///如果一个模型中 包含一个数组 数组中是另一个模型
|
||||||
|
+ (NSDictionary *)objectClassInArray;
|
||||||
|
///如果一个模型中需要字段映射的话 比如id -> ID name -> other.name
|
||||||
|
+ (NSDictionary *)replacedKeyFromPropertyName;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
55
xplan-ios/Base/MVP/Model/BaseObject.m
Normal file
55
xplan-ios/Base/MVP/Model/BaseObject.m
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// BaseObject.m
|
||||||
|
// xplan-ios
|
||||||
|
//
|
||||||
|
// Created by 冯硕 on 2021/9/9.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "BaseObject.h"
|
||||||
|
#import <MJExtension/MJExtension.h>
|
||||||
|
|
||||||
|
@implementation BaseObject
|
||||||
|
|
||||||
|
/// 依据数组初始化一个实例数组
|
||||||
|
/// @param json json 数据
|
||||||
|
+ (NSArray *)modelsWithArray:(id)json {
|
||||||
|
return [self mj_objectArrayWithKeyValuesArray:json];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 依据字典初始化一个实例
|
||||||
|
/// @param dictionary 字典
|
||||||
|
+ (instancetype)modelWithDictionary:(NSDictionary *)dictionary {
|
||||||
|
return [self mj_objectWithKeyValues:dictionary];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 依据JSON对象初始化一个实例
|
||||||
|
/// @param json json 数据
|
||||||
|
+ (instancetype)modelWithJSON:(id)json {
|
||||||
|
return [self mj_objectWithKeyValues:json];
|
||||||
|
}
|
||||||
|
|
||||||
|
///model 转字典
|
||||||
|
- (NSDictionary *)model2dictionary {
|
||||||
|
return [[self mj_keyValues] copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
///如果模型中包含数组的话
|
||||||
|
+ (NSDictionary *)mj_objectClassInArray {
|
||||||
|
return [self objectClassInArray];
|
||||||
|
}
|
||||||
|
|
||||||
|
///模型中需要映射 重写整个方法
|
||||||
|
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
|
||||||
|
return [self replacedKeyFromPropertyName];
|
||||||
|
}
|
||||||
|
|
||||||
|
///扩展方法 按需索取 重写即可
|
||||||
|
///如果一个模型中 包含一个数组 数组中是另一个模型
|
||||||
|
+ (NSDictionary *)objectClassInArray {
|
||||||
|
return @{};
|
||||||
|
}
|
||||||
|
///如果一个模型中需要字段映射的话 比如id -> ID name -> other.name
|
||||||
|
+ (NSDictionary *)replacedKeyFromPropertyName {
|
||||||
|
return @{};
|
||||||
|
}
|
||||||
|
@end
|
@@ -55,9 +55,9 @@
|
|||||||
AFHTTPSessionManager *manager = [HttpRequestHelper requestManager];
|
AFHTTPSessionManager *manager = [HttpRequestHelper requestManager];
|
||||||
[manager GET:method parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
[manager GET:method parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NSLog(@"\n%@", [responseObject yy_modelToJSONString]);
|
NSLog(@"\n%@", responseObject);
|
||||||
#endif
|
#endif
|
||||||
BaseModel *baseModel = [BaseModel yy_modelWithDictionary:responseObject];
|
BaseModel *baseModel = [BaseModel modelWithDictionary:responseObject];
|
||||||
if (baseModel.code == 200) {
|
if (baseModel.code == 200) {
|
||||||
success(baseModel);
|
success(baseModel);
|
||||||
} else {
|
} else {
|
||||||
@@ -96,9 +96,9 @@
|
|||||||
AFHTTPSessionManager *manager = [HttpRequestHelper requestManager];
|
AFHTTPSessionManager *manager = [HttpRequestHelper requestManager];
|
||||||
[manager POST:method parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
[manager POST:method parameters:params headers:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
NSLog(@"\n%@", [responseObject yy_modelToJSONString]);
|
NSLog(@"\n%@", responseObject);
|
||||||
#endif
|
#endif
|
||||||
BaseModel *baseModel = [BaseModel yy_modelWithDictionary:responseObject];
|
BaseModel *baseModel = [BaseModel modelWithDictionary:responseObject];
|
||||||
if (baseModel.code == 200) {
|
if (baseModel.code == 200) {
|
||||||
success(baseModel);
|
success(baseModel);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
- (void)phoneQuickLogin:(NSString *)accessToken token:(NSString *)token {
|
- (void)phoneQuickLogin:(NSString *)accessToken token:(NSString *)token {
|
||||||
[Api phoneQuickLogin:[self createHttpCompletion:^(BaseModel *data) {
|
[Api phoneQuickLogin:[self createHttpCompletion:^(BaseModel *data) {
|
||||||
[[AccountInfoStorage instance] saveAccountInfo:[AccountModel yy_modelWithDictionary:data.data]];
|
[[AccountInfoStorage instance] saveAccountInfo:[AccountModel modelWithDictionary:data.data]];
|
||||||
[[self getView] phoneQuickLoginSuccess];
|
[[self getView] phoneQuickLoginSuccess];
|
||||||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||||||
// todo fail
|
// todo fail
|
||||||
|
Reference in New Issue
Block a user