feat: 更新 Bridging Header 和错误信息文件以支持新模型
主要变更: 1. 在 Bridging Header 中添加了对 PIBaseModel 和 MomentsInfoModel 的引用,以支持新的数据模型。 2. 更新了 error message.txt 文件,增加了详细的编译错误信息,帮助开发者快速定位问题。 3. 在 .gitignore 中添加了 error message.txt,以避免将错误信息文件纳入版本控制。 此更新旨在提升代码的可维护性和调试效率,确保新模型的顺利集成。
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -16,3 +16,4 @@ YuMi/Assets.xcassets/
|
|||||||
|
|
||||||
# Documentation files
|
# Documentation files
|
||||||
*.md
|
*.md
|
||||||
|
error message.txt
|
||||||
|
@@ -18,32 +18,24 @@ import Foundation
|
|||||||
/// - failure: 失败回调 (错误码, 错误信息)
|
/// - failure: 失败回调 (错误码, 错误信息)
|
||||||
@objc func fetchLatestMomentsWithNextID(
|
@objc func fetchLatestMomentsWithNextID(
|
||||||
_ nextID: String,
|
_ nextID: String,
|
||||||
completion: @escaping (NSArray, String) -> Void,
|
completion: @escaping ([MomentsInfoModel], String) -> Void,
|
||||||
failure: @escaping (Int, String) -> Void
|
failure: @escaping (Int, String) -> Void
|
||||||
) {
|
) {
|
||||||
let pageSize = "20"
|
let pageSize = "20"
|
||||||
let types = "0,2" // 图片+文字
|
let types = "0,2" // 图片+文字
|
||||||
|
|
||||||
Api.momentsLatestList({ (data, code, msg) in
|
Api.momentsLatestList({ (data, code, msg) in
|
||||||
if code == 200 {
|
if code == 200, let dict = data?.data as? NSDictionary {
|
||||||
// 使用运行时动态调用解析 Model,避免类型依赖
|
// 从返回数据中提取原始 dictionary 数组
|
||||||
if let modelClass = NSClassFromString("MomentsListInfoModel") as? NSObject.Type,
|
if let listArray = dict["dynamicList"] as? NSArray {
|
||||||
let selector = NSSelectorFromString("modelWithDictionary:") as Selector?,
|
// MJExtension 在 Swift 中的正确用法(返回 NSMutableArray)
|
||||||
modelClass.responds(to: selector) {
|
let modelsArray = MomentsInfoModel.mj_objectArray(withKeyValuesArray: listArray)
|
||||||
|
let nextID = dict["nextDynamicId"] as? String ?? ""
|
||||||
let modelObj = modelClass.perform(selector, with: data?.data)?.takeUnretainedValue()
|
// 将 NSMutableArray 转换为 NSArray 传递给 OC
|
||||||
|
completion(modelsArray as? [MomentsInfoModel] ?? [], nextID)
|
||||||
// 使用 KVC 获取属性,避免直接访问类型
|
} else {
|
||||||
if let model = modelObj as? NSObject {
|
completion([], "")
|
||||||
let dynamicList = model.value(forKey: "dynamicList") as? NSArray ?? NSArray()
|
|
||||||
let nextID = model.value(forKey: "nextDynamicId") as? String ?? ""
|
|
||||||
completion(dynamicList, nextID)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析失败,返回空
|
|
||||||
completion(NSArray(), "")
|
|
||||||
} else {
|
} else {
|
||||||
failure(Int(code), msg ?? "请求失败")
|
failure(Int(code), msg ?? "请求失败")
|
||||||
}
|
}
|
||||||
|
@@ -87,7 +87,7 @@
|
|||||||
|
|
||||||
@kWeakify(self);
|
@kWeakify(self);
|
||||||
[self.api fetchLatestMomentsWithNextID:self.nextID
|
[self.api fetchLatestMomentsWithNextID:self.nextID
|
||||||
completion:^(NSArray<MomentsInfoModel *> *list, NSString *nextMomentID) {
|
completion:^(NSArray<MomentsInfoModel *> * _Nonnull list, NSString * _Nonnull nextMomentID) {
|
||||||
@kStrongify(self);
|
@kStrongify(self);
|
||||||
[self endLoading];
|
[self endLoading];
|
||||||
if (list.count > 0) {
|
if (list.count > 0) {
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
[self.tableView.mj_footer endRefreshing];
|
[self.tableView.mj_footer endRefreshing];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} failure:^(NSInteger code, NSString *msg) {
|
} failure:^(NSInteger code, NSString * _Nonnull msg) {
|
||||||
@kStrongify(self);
|
@kStrongify(self);
|
||||||
[self endLoading];
|
[self endLoading];
|
||||||
// TODO: 完全没有数据情况下,后续补充数据异常页面
|
// TODO: 完全没有数据情况下,后续补充数据异常页面
|
||||||
|
@@ -29,14 +29,21 @@
|
|||||||
// MARK: - Image Upload & Progress HUD
|
// MARK: - Image Upload & Progress HUD
|
||||||
#import "MBProgressHUD.h"
|
#import "MBProgressHUD.h"
|
||||||
|
|
||||||
|
// MARK: - Base Model & Types
|
||||||
|
#import "PIBaseModel.h"
|
||||||
|
#import "YUMINNNN.h"
|
||||||
|
|
||||||
// MARK: - API & Models
|
// MARK: - API & Models
|
||||||
#import "Api+Moments.h"
|
#import "Api+Moments.h"
|
||||||
#import "Api+Mine.h"
|
#import "Api+Mine.h"
|
||||||
#import "AccountInfoStorage.h"
|
#import "AccountInfoStorage.h"
|
||||||
|
#import "MomentsInfoModel.h"
|
||||||
|
#import "MomentsListInfoModel.h"
|
||||||
|
|
||||||
// MARK: - Utilities
|
// MARK: - Utilities
|
||||||
#import "UIImage+Utils.h"
|
#import "UIImage+Utils.h"
|
||||||
#import "NSString+Utils.h"
|
#import "NSString+Utils.h"
|
||||||
|
#import <MJExtension/MJExtension.h>
|
||||||
|
|
||||||
// 注意:
|
// 注意:
|
||||||
// 1. EPMomentViewController 和 EPMineViewController 直接继承 UIViewController
|
// 1. EPMomentViewController 和 EPMineViewController 直接继承 UIViewController
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user