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:
@@ -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"=图片
|
||||
|
||||
Reference in New Issue
Block a user