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
|
||||
*.md
|
||||
error message.txt
|
||||
|
@@ -18,32 +18,24 @@ import Foundation
|
||||
/// - failure: 失败回调 (错误码, 错误信息)
|
||||
@objc func fetchLatestMomentsWithNextID(
|
||||
_ nextID: String,
|
||||
completion: @escaping (NSArray, String) -> Void,
|
||||
completion: @escaping ([MomentsInfoModel], String) -> Void,
|
||||
failure: @escaping (Int, String) -> Void
|
||||
) {
|
||||
let pageSize = "20"
|
||||
let types = "0,2" // 图片+文字
|
||||
|
||||
Api.momentsLatestList({ (data, code, msg) in
|
||||
if code == 200 {
|
||||
// 使用运行时动态调用解析 Model,避免类型依赖
|
||||
if let modelClass = NSClassFromString("MomentsListInfoModel") as? NSObject.Type,
|
||||
let selector = NSSelectorFromString("modelWithDictionary:") as Selector?,
|
||||
modelClass.responds(to: selector) {
|
||||
|
||||
let modelObj = modelClass.perform(selector, with: data?.data)?.takeUnretainedValue()
|
||||
|
||||
// 使用 KVC 获取属性,避免直接访问类型
|
||||
if let model = modelObj as? NSObject {
|
||||
let dynamicList = model.value(forKey: "dynamicList") as? NSArray ?? NSArray()
|
||||
let nextID = model.value(forKey: "nextDynamicId") as? String ?? ""
|
||||
completion(dynamicList, nextID)
|
||||
return
|
||||
}
|
||||
if code == 200, let dict = data?.data as? NSDictionary {
|
||||
// 从返回数据中提取原始 dictionary 数组
|
||||
if let listArray = dict["dynamicList"] as? NSArray {
|
||||
// MJExtension 在 Swift 中的正确用法(返回 NSMutableArray)
|
||||
let modelsArray = MomentsInfoModel.mj_objectArray(withKeyValuesArray: listArray)
|
||||
let nextID = dict["nextDynamicId"] as? String ?? ""
|
||||
// 将 NSMutableArray 转换为 NSArray 传递给 OC
|
||||
completion(modelsArray as? [MomentsInfoModel] ?? [], nextID)
|
||||
} else {
|
||||
completion([], "")
|
||||
}
|
||||
|
||||
// 解析失败,返回空
|
||||
completion(NSArray(), "")
|
||||
} else {
|
||||
failure(Int(code), msg ?? "请求失败")
|
||||
}
|
||||
|
@@ -87,7 +87,7 @@
|
||||
|
||||
@kWeakify(self);
|
||||
[self.api fetchLatestMomentsWithNextID:self.nextID
|
||||
completion:^(NSArray<MomentsInfoModel *> *list, NSString *nextMomentID) {
|
||||
completion:^(NSArray<MomentsInfoModel *> * _Nonnull list, NSString * _Nonnull nextMomentID) {
|
||||
@kStrongify(self);
|
||||
[self endLoading];
|
||||
if (list.count > 0) {
|
||||
@@ -107,7 +107,7 @@
|
||||
[self.tableView.mj_footer endRefreshing];
|
||||
}
|
||||
}
|
||||
} failure:^(NSInteger code, NSString *msg) {
|
||||
} failure:^(NSInteger code, NSString * _Nonnull msg) {
|
||||
@kStrongify(self);
|
||||
[self endLoading];
|
||||
// TODO: 完全没有数据情况下,后续补充数据异常页面
|
||||
|
@@ -29,14 +29,21 @@
|
||||
// MARK: - Image Upload & Progress HUD
|
||||
#import "MBProgressHUD.h"
|
||||
|
||||
// MARK: - Base Model & Types
|
||||
#import "PIBaseModel.h"
|
||||
#import "YUMINNNN.h"
|
||||
|
||||
// MARK: - API & Models
|
||||
#import "Api+Moments.h"
|
||||
#import "Api+Mine.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "MomentsInfoModel.h"
|
||||
#import "MomentsListInfoModel.h"
|
||||
|
||||
// MARK: - Utilities
|
||||
#import "UIImage+Utils.h"
|
||||
#import "NSString+Utils.h"
|
||||
#import <MJExtension/MJExtension.h>
|
||||
|
||||
// 注意:
|
||||
// 1. EPMomentViewController 和 EPMineViewController 直接继承 UIViewController
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user