feat: 添加 EPMomentAPIHelper_Deprecated 以支持旧版 API
主要变更: 1. 新增 EPMomentAPIHelper_Deprecated.h 和 EPMomentAPIHelper_Deprecated.m 文件,提供与旧版 Objective-C API 的兼容性。 2. 该文件已被 EPMomentAPISwiftHelper.swift 替代,保留仅供参考,后续可删除。 3. 更新 EPMomentListView 以使用新的 Swift 版本 API,提升代码的现代化和类型安全。 此更新旨在确保旧版 API 的平滑过渡,同时鼓励使用新的 Swift 实现。
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
//
|
||||
// EPMomentAPIHelper.h
|
||||
// EPMomentAPIHelper_Deprecated.h
|
||||
// YuMi
|
||||
//
|
||||
// Created by AI on 2025-10-10.
|
||||
//
|
||||
// ⚠️ DEPRECATED: 已被 EPMomentAPISwiftHelper.swift 替代
|
||||
// 原因:
|
||||
// 1. 继承 BaseMvpPresenter 会引起 Bridging Header 依赖链问题
|
||||
// 2. Swift 版本更简洁、类型安全
|
||||
// 3. 功能已完整迁移到 Swift 版本
|
||||
//
|
||||
// 保留此文件仅供参考,后续可删除
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "BaseMvpPresenter.h"
|
@@ -1,12 +1,14 @@
|
||||
//
|
||||
// EPMomentAPIHelper.m
|
||||
// EPMomentAPIHelper_Deprecated.m
|
||||
// YuMi
|
||||
//
|
||||
// Created by AI on 2025-10-10.
|
||||
//
|
||||
// ⚠️ DEPRECATED: 已被 EPMomentAPISwiftHelper.swift 替代
|
||||
// 保留此文件仅供参考,后续可删除
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "EPMomentAPIHelper.h"
|
||||
#import "EPMomentAPIHelper_Deprecated.h"
|
||||
#import "Api+Moments.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "BaseModel.h"
|
@@ -8,9 +8,48 @@
|
||||
import Foundation
|
||||
|
||||
/// 动态 API 封装(Swift 现代化版本)
|
||||
/// 与现有 OC 版本 EPMomentAPIHelper 并存,供对比评估
|
||||
/// 统一封装列表获取和发布功能,完全替代 OC 版本
|
||||
@objc class EPMomentAPISwiftHelper: NSObject {
|
||||
|
||||
/// 拉取最新动态列表
|
||||
/// - Parameters:
|
||||
/// - nextID: 下一页 ID,首次传空字符串
|
||||
/// - completion: 成功回调 (动态列表, 下一页ID)
|
||||
/// - failure: 失败回调 (错误码, 错误信息)
|
||||
@objc func fetchLatestMomentsWithNextID(
|
||||
_ nextID: String,
|
||||
completion: @escaping (NSArray, 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
|
||||
}
|
||||
}
|
||||
|
||||
// 解析失败,返回空
|
||||
completion(NSArray(), "")
|
||||
} else {
|
||||
failure(Int(code), msg ?? "请求失败")
|
||||
}
|
||||
}, dynamicId: nextID, pageSize: pageSize, types: types)
|
||||
}
|
||||
|
||||
/// 发布动态
|
||||
/// - Parameters:
|
||||
/// - type: "0"=纯文本, "2"=图片
|
||||
|
@@ -6,12 +6,18 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "EPMomentAPIHelper.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class EPMomentAPISwiftHelper;
|
||||
@class MomentsInfoModel;
|
||||
|
||||
/// 推荐/我的动态列表数据源类型
|
||||
typedef NS_ENUM(NSInteger, EPMomentListSourceType) {
|
||||
EPMomentListSourceTypeRecommend = 0,
|
||||
EPMomentListSourceTypeMine = 1
|
||||
};
|
||||
|
||||
/// 承载 Moments 列表与分页刷新的视图
|
||||
@interface EPMomentListView : UIView
|
||||
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#import "EPMomentListView.h"
|
||||
#import "EPMomentCell.h"
|
||||
#import <MJRefresh/MJRefresh.h>
|
||||
#import "YuMi-Swift.h"
|
||||
|
||||
|
||||
@interface EPMomentListView () <UITableViewDelegate, UITableViewDataSource>
|
||||
@@ -16,7 +17,7 @@
|
||||
@property (nonatomic, strong) UITableView *tableView;
|
||||
@property (nonatomic, strong) UIRefreshControl *refreshControl;
|
||||
@property (nonatomic, strong) NSMutableArray *mutableRawList;
|
||||
@property (nonatomic, strong) EPMomentAPIHelper *api;
|
||||
@property (nonatomic, strong) EPMomentAPISwiftHelper *api;
|
||||
@property (nonatomic, assign) BOOL isLoading;
|
||||
@property (nonatomic, copy) NSString *nextID;
|
||||
@property (nonatomic, assign) BOOL isLocalMode;
|
||||
@@ -29,7 +30,7 @@
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
self.backgroundColor = [UIColor clearColor];
|
||||
_api = [[EPMomentAPIHelper alloc] init];
|
||||
_api = [[EPMomentAPISwiftHelper alloc] init];
|
||||
_mutableRawList = [NSMutableArray array];
|
||||
_sourceType = EPMomentListSourceTypeRecommend;
|
||||
|
||||
@@ -86,7 +87,7 @@
|
||||
|
||||
@kWeakify(self);
|
||||
[self.api fetchLatestMomentsWithNextID:self.nextID
|
||||
completion:^(NSArray<MomentsInfoModel *> * _Nullable list, NSString * _Nonnull nextMomentID) {
|
||||
completion:^(NSArray<MomentsInfoModel *> *list, NSString *nextMomentID) {
|
||||
@kStrongify(self);
|
||||
[self endLoading];
|
||||
if (list.count > 0) {
|
||||
@@ -106,7 +107,7 @@
|
||||
[self.tableView.mj_footer endRefreshing];
|
||||
}
|
||||
}
|
||||
} failure:^(NSInteger code, NSString * _Nullable msg) {
|
||||
} failure:^(NSInteger code, NSString *msg) {
|
||||
@kStrongify(self);
|
||||
[self endLoading];
|
||||
// TODO: 完全没有数据情况下,后续补充数据异常页面
|
||||
|
Reference in New Issue
Block a user