You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
487 B

6 years ago
6 years ago
  1. //
  2. // ExtensionJSON.swift
  3. // GMERemittance
  4. //
  5. // Created by gme_2 on 22/08/2018.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import SwiftyJSON
  10. import ObjectMapper
  11. extension JSON {
  12. func map<T: Mappable>() -> [T]? {
  13. let json = self.array
  14. let mapped: [T]? = json?.compactMap({$0.map()})
  15. return mapped
  16. }
  17. func map<T: Mappable>() -> T? {
  18. let obj: T? = Mapper<T>().map(JSONObject: self.object)
  19. return obj
  20. }
  21. }