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.

100 lines
2.6 KiB

  1. //
  2. // EnumOperators.swift
  3. // ObjectMapper
  4. //
  5. // Created by Tristan Himmelman on 2016-09-26.
  6. // Copyright © 2016 hearst. All rights reserved.
  7. //
  8. import Foundation
  9. // MARK:- Raw Representable types
  10. /// Object of Raw Representable type
  11. public func <- <T: RawRepresentable>(left: inout T, right: Map) {
  12. left <- (right, EnumTransform())
  13. }
  14. public func >>> <T: RawRepresentable>(left: T, right: Map) {
  15. left >>> (right, EnumTransform())
  16. }
  17. /// Optional Object of Raw Representable type
  18. public func <- <T: RawRepresentable>(left: inout T?, right: Map) {
  19. left <- (right, EnumTransform())
  20. }
  21. public func >>> <T: RawRepresentable>(left: T?, right: Map) {
  22. left >>> (right, EnumTransform())
  23. }
  24. // Code targeting the Swift 4.1 compiler and below.
  25. #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
  26. /// Implicitly Unwrapped Optional Object of Raw Representable type
  27. public func <- <T: RawRepresentable>(left: inout T!, right: Map) {
  28. left <- (right, EnumTransform())
  29. }
  30. #endif
  31. // MARK:- Arrays of Raw Representable type
  32. /// Array of Raw Representable object
  33. public func <- <T: RawRepresentable>(left: inout [T], right: Map) {
  34. left <- (right, EnumTransform())
  35. }
  36. public func >>> <T: RawRepresentable>(left: [T], right: Map) {
  37. left >>> (right, EnumTransform())
  38. }
  39. /// Array of Raw Representable object
  40. public func <- <T: RawRepresentable>(left: inout [T]?, right: Map) {
  41. left <- (right, EnumTransform())
  42. }
  43. public func >>> <T: RawRepresentable>(left: [T]?, right: Map) {
  44. left >>> (right, EnumTransform())
  45. }
  46. // Code targeting the Swift 4.1 compiler and below.
  47. #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
  48. /// Array of Raw Representable object
  49. public func <- <T: RawRepresentable>(left: inout [T]!, right: Map) {
  50. left <- (right, EnumTransform())
  51. }
  52. #endif
  53. // MARK:- Dictionaries of Raw Representable type
  54. /// Dictionary of Raw Representable object
  55. public func <- <T: RawRepresentable>(left: inout [String: T], right: Map) {
  56. left <- (right, EnumTransform())
  57. }
  58. public func >>> <T: RawRepresentable>(left: [String: T], right: Map) {
  59. left >>> (right, EnumTransform())
  60. }
  61. /// Dictionary of Raw Representable object
  62. public func <- <T: RawRepresentable>(left: inout [String: T]?, right: Map) {
  63. left <- (right, EnumTransform())
  64. }
  65. public func >>> <T: RawRepresentable>(left: [String: T]?, right: Map) {
  66. left >>> (right, EnumTransform())
  67. }
  68. // Code targeting the Swift 4.1 compiler and below.
  69. #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
  70. /// Dictionary of Raw Representable object
  71. public func <- <T: RawRepresentable>(left: inout [String: T]!, right: Map) {
  72. left <- (right, EnumTransform())
  73. }
  74. #endif