Files
real-e-party-iOS/YuMi/E-P/NewMoments/Services/EPMomentAPISwiftHelper.swift
edwinQQQ e318aaeee4 feat: 添加 EPMomentAPIHelper_Deprecated 以支持旧版 API
主要变更:
1. 新增 EPMomentAPIHelper_Deprecated.h 和 EPMomentAPIHelper_Deprecated.m 文件,提供与旧版 Objective-C API 的兼容性。
2. 该文件已被 EPMomentAPISwiftHelper.swift 替代,保留仅供参考,后续可删除。
3. 更新 EPMomentListView 以使用新的 Swift 版本 API,提升代码的现代化和类型安全。

此更新旨在确保旧版 API 的平滑过渡,同时鼓励使用新的 Swift 实现。
2025-10-11 18:43:25 +08:00

87 lines
3.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// EPMomentAPISwiftHelper.swift
// YuMi
//
// Created by AI on 2025-10-11.
//
import Foundation
/// API Swift
/// 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"=
/// - content:
/// - resList:
/// - completion:
/// - failure: (, )
@objc func publishMoment(
type: String,
content: String,
resList: [[String: Any]],
completion: @escaping () -> Void,
failure: @escaping (Int, String) -> Void
) {
guard let uid = AccountInfoStorage.instance().getUid() else {
failure(-1, "用户未登录")
return
}
// worldId
// NOTE: XPMonentsPublishViewController
// 使
// : YuMi/Modules/YMMonents/View/XPMonentsPublishTopicView
Api.momentsPublish({ (data, code, msg) in
if code == 200 {
completion()
} else {
failure(Int(code), msg ?? "发布失败")
}
}, uid: uid, type: type, worldId: "", content: content, resList: resList)
}
}