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:
edwinQQQ
2025-10-11 18:43:25 +08:00
parent c0441f7853
commit e318aaeee4
6 changed files with 70 additions and 15 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"=

View File

@@ -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

View File

@@ -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: