CoreMessage_TMessageUtil.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // CoreMessage_TMessageUtil.swift
  3. // Runner
  4. //
  5. // Created by Yayan Dwi on 15/04/20.
  6. // Copyright © 2020 The Chromium Authors. All rights reserved.
  7. //
  8. import Foundation
  9. public class CoreMessage_TMessageUtil {
  10. private static var mTID = NSDate().timeIntervalSince1970 * 1000
  11. public static func getTID() -> String {
  12. mTID = Double(Int(mTID) + Int(1))
  13. return String(Int(mTID))
  14. }
  15. public static func getString(json: Any, key: String) -> String {
  16. return getString(json: json, key: key, def: "")
  17. }
  18. public static func getString(json: Any, key: String, def: String) -> String {
  19. if let dict = json as? [String: Any], let value = dict[key] as? String {
  20. if !value.isEmpty {
  21. return value
  22. }
  23. }
  24. return def
  25. }
  26. public static func getInt(json: Any, key: String, def: Int) -> Int {
  27. if let dict = json as? [String: Any], let value = dict[key] as? Int {
  28. return value
  29. }
  30. return def
  31. }
  32. public static func getIntAsString(json: Any, key: String, def: Int) -> String {
  33. return String(getInt(json: json, key: key, def: def))
  34. }
  35. public static func getLong(json: Any, key: String, def: CLong) -> CLong {
  36. if let dict = json as? [String: Any], let value = dict[key] as? CLong {
  37. return value
  38. }
  39. return def
  40. }
  41. }