| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // Dictionary+Response.swift
- // MiMoLive
- //
- // Created by OneeChan on 2025/9/18.
- //
- import Foundation
- extension Dictionary<AnyHashable, Any> {
- var data: [AnyHashable: Any]? {
- self["data"] as? [AnyHashable: Any]
- }
-
- var code: Int {
- intValue(for: "code")
- }
-
- var isCodeSuccess: Bool {
- let code = code
- return code == 0 || code == 200
- }
-
- func intValue(for key: String, _ defaultValue: Int = 0) -> Int {
- guard let value = self[key] else { return defaultValue }
- let intValue: Int? = if let intValue = value as? Int {
- intValue
- } else if let strValue = value as? String {
- Int(strValue)
- } else {
- nil
- }
- return intValue ?? defaultValue
- }
-
- func showNetError() {
- guard let err = MODataManager.objectOrNil(forKey: "msg", from: self) as? String else { return }
- if err.isEmpty {
- MBProgressHUD.showTipMessage(inWindow: NSLocalizedString("mimo_common_data_error", comment: ""))
- } else {
- MBProgressHUD.showTipMessage(inWindow: err)
- }
- }
- }
|