diff --git a/Source/BuiltInBasicType.swift b/Source/BuiltInBasicType.swift index 8e44c18..4ea131d 100644 --- a/Source/BuiltInBasicType.swift +++ b/Source/BuiltInBasicType.swift @@ -21,8 +21,8 @@ import Foundation protocol _BuiltInBasicType: _Transformable { - static func _transform(from object: Any) -> Self? - func _plainValue() -> Any? + static func _transform(from object: Any, transformer: _Transformer?) -> Self? + func _plainValue(transformer: _Transformer?) -> Any? } // Suppport integer type @@ -34,7 +34,10 @@ protocol IntegerPropertyProtocol: FixedWidthInteger, _BuiltInBasicType { extension IntegerPropertyProtocol { - static func _transform(from object: Any) -> Self? { + static func _transform(from object: Any, transformer: _Transformer?) -> Self? { + if let result = transformer?.transform(from: object, type: self) { + return result + } switch object { case let str as String: return Self(str, radix: 10) @@ -45,7 +48,10 @@ extension IntegerPropertyProtocol { } } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } @@ -63,7 +69,10 @@ extension UInt64: IntegerPropertyProtocol {} extension Bool: _BuiltInBasicType { - static func _transform(from object: Any) -> Bool? { + static func _transform(from object: Any, transformer: _Transformer?) -> Bool? { + if let result = transformer?.transform(from: object, type: self) { + return result + } switch object { case let str as NSString: let lowerCase = str.lowercased @@ -81,7 +90,10 @@ extension Bool: _BuiltInBasicType { } } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } @@ -94,7 +106,10 @@ protocol FloatPropertyProtocol: _BuiltInBasicType, LosslessStringConvertible { extension FloatPropertyProtocol { - static func _transform(from object: Any) -> Self? { + static func _transform(from object: Any, transformer: _Transformer?) -> Self? { + if let result = transformer?.transform(from: object, type: self) { + return result + } switch object { case let str as String: return Self(str) @@ -105,7 +120,10 @@ extension FloatPropertyProtocol { } } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } @@ -123,7 +141,10 @@ fileprivate let formatter: NumberFormatter = { extension String: _BuiltInBasicType { - static func _transform(from object: Any) -> String? { + static func _transform(from object: Any, transformer: _Transformer?) -> String? { + if let result = transformer?.transform(from: object, type: self) { + return result + } switch object { case let str as String: return str @@ -144,7 +165,10 @@ extension String: _BuiltInBasicType { } } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } @@ -153,8 +177,11 @@ extension String: _BuiltInBasicType { extension Optional: _BuiltInBasicType { - static func _transform(from object: Any) -> Optional? { - if let value = (Wrapped.self as? _Transformable.Type)?.transform(from: object) as? Wrapped { + static func _transform(from object: Any, transformer: _Transformer?) -> Optional? { + if let result = transformer?.transform(from: object, type: self) { + return result + } + if let value = (Wrapped.self as? _Transformable.Type)?.transform(from: object, transformer: transformer) as? Wrapped { return Optional(value) } else if let value = object as? Wrapped { return Optional(value) @@ -168,10 +195,13 @@ extension Optional: _BuiltInBasicType { }) } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } if let value = _getWrappedValue() { if let transformable = value as? _Transformable { - return transformable.plainValue() + return transformable.plainValue(transformer: transformer) } else { return value } @@ -184,7 +214,7 @@ extension Optional: _BuiltInBasicType { extension Collection { - static func _collectionTransform(from object: Any) -> [Iterator.Element]? { + static func _collectionTransform(from object: Any, transformer: _Transformer?) -> [Iterator.Element]? { guard let arr = object as? [Any] else { InternalLogger.logDebug("Expect object to be an array but it's not") return nil @@ -192,7 +222,7 @@ extension Collection { typealias Element = Iterator.Element var result: [Element] = [Element]() arr.forEach { (each) in - if let element = (Element.self as? _Transformable.Type)?.transform(from: each) as? Element { + if let element = (Element.self as? _Transformable.Type)?.transform(from: each, transformer: transformer) as? Element { result.append(element) } else if let element = each as? Element { result.append(element) @@ -201,11 +231,14 @@ extension Collection { return result } - func _collectionPlainValue() -> Any? { + func _collectionPlainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } typealias Element = Iterator.Element var result: [Any] = [Any]() self.forEach { (each) in - if let transformable = each as? _Transformable, let transValue = transformable.plainValue() { + if let transformable = each as? _Transformable, let transValue = transformable.plainValue(transformer: transformer) { result.append(transValue) } else { InternalLogger.logError("value: \(each) isn't transformable type!") @@ -217,26 +250,32 @@ extension Collection { extension Array: _BuiltInBasicType { - static func _transform(from object: Any) -> [Element]? { - return self._collectionTransform(from: object) + static func _transform(from object: Any, transformer: _Transformer?) -> [Element]? { + if let result = transformer?.transform(from: object, type: self) { + return result + } + return self._collectionTransform(from: object, transformer: transformer) } - func _plainValue() -> Any? { - return self._collectionPlainValue() + func _plainValue(transformer: _Transformer?) -> Any? { + return self._collectionPlainValue(transformer: transformer) } } extension Set: _BuiltInBasicType { - static func _transform(from object: Any) -> Set? { - if let arr = self._collectionTransform(from: object) { + static func _transform(from object: Any, transformer: _Transformer?) -> Set? { + if let result = transformer?.transform(from: object, type: self) { + return result + } + if let arr = self._collectionTransform(from: object, transformer: transformer) { return Set(arr) } return nil } - func _plainValue() -> Any? { - return self._collectionPlainValue() + func _plainValue(transformer: _Transformer?) -> Any? { + return self._collectionPlainValue(transformer: transformer) } } @@ -244,7 +283,10 @@ extension Set: _BuiltInBasicType { extension Dictionary: _BuiltInBasicType { - static func _transform(from object: Any) -> [Key: Value]? { + static func _transform(from object: Any, transformer: _Transformer?) -> [Key: Value]? { + if let result = transformer?.transform(from: object, type: self) { + return result + } guard let dict = object as? [String: Any] else { InternalLogger.logDebug("Expect object to be an NSDictionary but it's not") return nil @@ -252,7 +294,7 @@ extension Dictionary: _BuiltInBasicType { var result = [Key: Value]() for (key, value) in dict { if let sKey = key as? Key { - if let nValue = (Value.self as? _Transformable.Type)?.transform(from: value) as? Value { + if let nValue = (Value.self as? _Transformable.Type)?.transform(from: value, transformer: transformer) as? Value { result[sKey] = nValue } else if let nValue = value as? Value { result[sKey] = nValue @@ -262,12 +304,15 @@ extension Dictionary: _BuiltInBasicType { return result } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } var result = [String: Any]() for (key, value) in self { if let key = key as? String { if let transformable = value as? _Transformable { - if let transValue = transformable.plainValue() { + if let transValue = transformable.plainValue(transformer: transformer) { result[key] = transValue } } diff --git a/Source/BuiltInBridgeType.swift b/Source/BuiltInBridgeType.swift index 53fadd6..9cb1d32 100644 --- a/Source/BuiltInBridgeType.swift +++ b/Source/BuiltInBridgeType.swift @@ -10,27 +10,33 @@ import Foundation protocol _BuiltInBridgeType: _Transformable { - static func _transform(from object: Any) -> _BuiltInBridgeType? - func _plainValue() -> Any? + static func _transform(from object: Any, transformer: _Transformer?) -> _BuiltInBridgeType? + func _plainValue(transformer: _Transformer?) -> Any? } extension NSString: _BuiltInBridgeType { - static func _transform(from object: Any) -> _BuiltInBridgeType? { - if let str = String.transform(from: object) { + static func _transform(from object: Any, transformer: _Transformer?) -> _BuiltInBridgeType? { + if let str = String.transform(from: object, transformer: transformer) { return NSString(string: str) } return nil } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } extension NSNumber: _BuiltInBridgeType { - static func _transform(from object: Any) -> _BuiltInBridgeType? { + static func _transform(from object: Any, transformer: _Transformer?) -> _BuiltInBridgeType? { + if let result = transformer?.transform(from: object, type: self) { + return result + } switch object { case let num as NSNumber: return num @@ -51,29 +57,38 @@ extension NSNumber: _BuiltInBridgeType { } } - func _plainValue() -> Any? { + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self } } extension NSArray: _BuiltInBridgeType { - static func _transform(from object: Any) -> _BuiltInBridgeType? { + static func _transform(from object: Any, transformer: _Transformer?) -> _BuiltInBridgeType? { + if let result = transformer?.transform(from: object, type: self) { + return result + } return object as? NSArray } - func _plainValue() -> Any? { - return (self as? Array)?.plainValue() + func _plainValue(transformer: _Transformer?) -> Any? { + return (self as? Array)?.plainValue(transformer: transformer) } } extension NSDictionary: _BuiltInBridgeType { - static func _transform(from object: Any) -> _BuiltInBridgeType? { + static func _transform(from object: Any, transformer: _Transformer?) -> _BuiltInBridgeType? { + if let result = transformer?.transform(from: object, type: self) { + return result + } return object as? NSDictionary } - func _plainValue() -> Any? { - return (self as? Dictionary)?.plainValue() + func _plainValue(transformer: _Transformer?) -> Any? { + return (self as? Dictionary)?.plainValue(transformer: transformer) } } diff --git a/Source/Custom/Transformer.swift b/Source/Custom/Transformer.swift new file mode 100644 index 0000000..286eac5 --- /dev/null +++ b/Source/Custom/Transformer.swift @@ -0,0 +1,22 @@ +// +// Transformer.swift +// HandyJSON +// +// Created by η†ŠζœδΌŸ on 2021/1/15. +// + +import Foundation + +public protocol _Transformer { + func transform(from object: Any, type: [K:V].Type) -> [K:V]? + func transform(from object: Any, type: [T].Type) -> [T]? + func transform(from object: Any, type: T.Type) -> T? + func plainValue(from object: T) -> Any? +} + +extension _Transformer { + public func transform(from object: Any, type: [K:V].Type) -> [K:V]? { nil } + public func transform(from object: Any, type: [T].Type) -> [T]? { nil } + public func transform(from object: Any, type: T.Type) -> T? { nil } + public func plainValue(from object: T) -> Any? { nil } +} diff --git a/Source/Deserializer.swift b/Source/Deserializer.swift index 150c929..289d24e 100644 --- a/Source/Deserializer.swift +++ b/Source/Deserializer.swift @@ -63,33 +63,33 @@ public class JSONDeserializer { /// Finds the internal dictionary in `dict` as the `designatedPath` specified, and map it to a Model /// `designatedPath` is a string like `result.data.orderInfo`, which each element split by `.` represents key of each layer, or nil - public static func deserializeFrom(dict: NSDictionary?, designatedPath: String? = nil) -> T? { - return deserializeFrom(dict: dict as? [String: Any], designatedPath: designatedPath) + public static func deserializeFrom(dict: NSDictionary?, designatedPath: String? = nil, transformer: _Transformer? = nil) -> T? { + return deserializeFrom(dict: dict as? [String: Any], designatedPath: designatedPath, transformer: transformer) } /// Finds the internal dictionary in `dict` as the `designatedPath` specified, and map it to a Model /// `designatedPath` is a string like `result.data.orderInfo`, which each element split by `.` represents key of each layer, or nil - public static func deserializeFrom(dict: [String: Any]?, designatedPath: String? = nil) -> T? { + public static func deserializeFrom(dict: [String: Any]?, designatedPath: String? = nil, transformer: _Transformer? = nil) -> T? { var targetDict = dict if let path = designatedPath { targetDict = getInnerObject(inside: targetDict, by: path) as? [String: Any] } if let _dict = targetDict { - return T._transform(dict: _dict) as? T + return T._transform(dict: _dict, transformer: transformer) as? T } return nil } /// Finds the internal JSON field in `json` as the `designatedPath` specified, and converts it to Model /// `designatedPath` is a string like `result.data.orderInfo`, which each element split by `.` represents key of each layer, or nil - public static func deserializeFrom(json: String?, designatedPath: String? = nil) -> T? { + public static func deserializeFrom(json: String?, designatedPath: String? = nil, transformer: _Transformer? = nil) -> T? { guard let _json = json else { return nil } do { let jsonObject = try JSONSerialization.jsonObject(with: _json.data(using: String.Encoding.utf8)!, options: .allowFragments) if let jsonDict = jsonObject as? NSDictionary { - return self.deserializeFrom(dict: jsonDict, designatedPath: designatedPath) + return self.deserializeFrom(dict: jsonDict, designatedPath: designatedPath, transformer: transformer) } } catch let error { InternalLogger.logError(error) @@ -99,13 +99,13 @@ public class JSONDeserializer { /// Finds the internal dictionary in `dict` as the `designatedPath` specified, and use it to reassign an exist model /// `designatedPath` is a string like `result.data.orderInfo`, which each element split by `.` represents key of each layer, or nil - public static func update(object: inout T, from dict: [String: Any]?, designatedPath: String? = nil) { + public static func update(object: inout T, from dict: [String: Any]?, designatedPath: String? = nil, transformer: _Transformer? = nil) { var targetDict = dict if let path = designatedPath { targetDict = getInnerObject(inside: targetDict, by: path) as? [String: Any] } if let _dict = targetDict { - T._transform(dict: _dict, to: &object) + T._transform(dict: _dict, to: &object, transformer: transformer) } } diff --git a/Source/EnumType.swift b/Source/EnumType.swift index 378546f..a35c116 100644 --- a/Source/EnumType.swift +++ b/Source/EnumType.swift @@ -10,22 +10,28 @@ import Foundation public protocol _RawEnumProtocol: _Transformable { - static func _transform(from object: Any) -> Self? - func _plainValue() -> Any? + static func _transform(from object: Any, transformer: _Transformer?) -> Self? + func _plainValue(transformer: _Transformer?) -> Any? } extension RawRepresentable where Self: _RawEnumProtocol { - public static func _transform(from object: Any) -> Self? { + public static func _transform(from object: Any, transformer: _Transformer?) -> Self? { + if let result = transformer?.transform(from: object, type: self) { + return result + } if let transformableType = RawValue.self as? _Transformable.Type { - if let typedValue = transformableType.transform(from: object) { + if let typedValue = transformableType.transform(from: object, transformer: transformer) { return Self(rawValue: typedValue as! RawValue) } } return nil } - public func _plainValue() -> Any? { + public func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } return self.rawValue } } diff --git a/Source/Export.swift b/Source/Export.swift index cef2a10..91db958 100644 --- a/Source/Export.swift +++ b/Source/Export.swift @@ -13,3 +13,5 @@ public protocol HandyJSONCustomTransformable: _ExtendCustomBasicType {} public protocol HandyJSON: _ExtendCustomModelType {} public protocol HandyJSONEnum: _RawEnumProtocol {} + +public protocol HandyJSONTransformer: _Transformer {} diff --git a/Source/ExtendCustomBasicType.swift b/Source/ExtendCustomBasicType.swift index 9ee9610..fbc1bfa 100644 --- a/Source/ExtendCustomBasicType.swift +++ b/Source/ExtendCustomBasicType.swift @@ -23,6 +23,6 @@ public protocol _ExtendCustomBasicType: _Transformable { - static func _transform(from object: Any) -> Self? - func _plainValue() -> Any? + static func _transform(from object: Any, transformer: _Transformer?) -> Self? + func _plainValue(transformer: _Transformer?) -> Any? } diff --git a/Source/ExtendCustomModelType.swift b/Source/ExtendCustomModelType.swift index 781b007..3bb6c9f 100644 --- a/Source/ExtendCustomModelType.swift +++ b/Source/ExtendCustomModelType.swift @@ -52,13 +52,13 @@ fileprivate func getRawValueFrom(dict: [String: Any], property: PropertyInfo, ma return dict[property.key] } -fileprivate func convertValue(rawValue: Any, property: PropertyInfo, mapper: HelpingMapper) -> Any? { +fileprivate func convertValue(rawValue: Any, property: PropertyInfo, mapper: HelpingMapper, transformer: _Transformer?) -> Any? { if rawValue is NSNull { return nil } if let mappingHandler = mapper.getMappingHandler(key: Int(bitPattern: property.address)), let transformer = mappingHandler.assignmentClosure { return transformer(rawValue) } if let transformableType = property.type as? _Transformable.Type { - return transformableType.transform(from: rawValue) + return transformableType.transform(from: rawValue, transformer: transformer) } else { return extensions(of: property.type).takeValue(from: rawValue) } @@ -112,15 +112,18 @@ extension NSObject { extension _ExtendCustomModelType { - static func _transform(from object: Any) -> Self? { + static func _transform(from object: Any, transformer: _Transformer?) -> Self? { + if let result = transformer?.transform(from: object, type: self) { + return result + } if let dict = object as? [String: Any] { // nested object, transform recursively - return self._transform(dict: dict) as? Self + return self._transform(dict: dict, transformer: transformer) as? Self } return nil } - static func _transform(dict: [String: Any]) -> _ExtendCustomModelType? { + static func _transform(dict: [String: Any], transformer: _Transformer?) -> _ExtendCustomModelType? { var instance: Self if let _nsType = Self.self as? NSObject.Type { @@ -129,12 +132,12 @@ extension _ExtendCustomModelType { instance = Self.init() } instance.willStartMapping() - _transform(dict: dict, to: &instance) + _transform(dict: dict, to: &instance, transformer: transformer) instance.didFinishMapping() return instance } - static func _transform(dict: [String: Any], to instance: inout Self) { + static func _transform(dict: [String: Any], to instance: inout Self, transformer: _Transformer?) { guard let properties = getProperties(forType: Self.self) else { InternalLogger.logDebug("Failed when try to get properties from type: \(type(of: Self.self))") return @@ -168,7 +171,7 @@ extension _ExtendCustomModelType { InternalLogger.logVerbose("field: ", property.key, " offset: ", property.offset, " isBridgeProperty: ", isBridgedProperty) if let rawValue = getRawValueFrom(dict: _dict, property: propertyDetail, mapper: mapper) { - if let convertedValue = convertValue(rawValue: rawValue, property: propertyDetail, mapper: mapper) { + if let convertedValue = convertValue(rawValue: rawValue, property: propertyDetail, mapper: mapper, transformer: transformer) { assignProperty(convertedValue: convertedValue, instance: instance, property: propertyDetail) continue } @@ -180,16 +183,19 @@ extension _ExtendCustomModelType { extension _ExtendCustomModelType { - func _plainValue() -> Any? { - return Self._serializeAny(object: self) + func _plainValue(transformer: _Transformer?) -> Any? { + if let result = transformer?.plainValue(from: self) { + return result + } + return Self._serializeAny(object: self, transformer: transformer) } - static func _serializeAny(object: _Transformable) -> Any? { + static func _serializeAny(object: _Transformable, transformer: _Transformer?) -> Any? { let mirror = Mirror(reflecting: object) guard let displayStyle = mirror.displayStyle else { - return object.plainValue() + return object.plainValue(transformer: transformer) } // after filtered by protocols above, now we expect the type is pure struct/class @@ -222,13 +228,13 @@ extension _ExtendCustomModelType { let requiredInfo = merge(children: children, propertyInfos: propertyInfos) - return _serializeModelObject(instance: mutableObject, properties: requiredInfo, mapper: mapper) as Any + return _serializeModelObject(instance: mutableObject, properties: requiredInfo, mapper: mapper, transformer: transformer) as Any default: - return object.plainValue() + return object.plainValue(transformer: transformer) } } - static func _serializeModelObject(instance: _ExtendCustomModelType, properties: [String: (Any, PropertyInfo?)], mapper: HelpingMapper) -> [String: Any] { + static func _serializeModelObject(instance: _ExtendCustomModelType, properties: [String: (Any, PropertyInfo?)], mapper: HelpingMapper, transformer: _Transformer?) -> [String: Any] { var dict = [String: Any]() for (key, property) in properties { @@ -261,7 +267,7 @@ extension _ExtendCustomModelType { } if let typedValue = realValue as? _Transformable { - if let result = self._serializeAny(object: typedValue) { + if let result = self._serializeAny(object: typedValue, transformer: transformer) { dict[realKey] = result continue } diff --git a/Source/HelpingMapper.swift b/Source/HelpingMapper.swift index 209f1e5..a5f8207 100644 --- a/Source/HelpingMapper.swift +++ b/Source/HelpingMapper.swift @@ -102,7 +102,7 @@ public class HelpingMapper { self.specify(property: &property, name: nil, converter: converter) } - public func specify(property: inout T, name: String?, converter: ((String) -> T)?) { + public func specify(property: inout T, name: String?, converter: ((String) -> T)?, transformer: _Transformer? = nil) { let pointer = withUnsafePointer(to: &property, { return $0 }) let key = Int(bitPattern: pointer) let names = (name == nil ? nil : [name!]) @@ -111,7 +111,7 @@ public class HelpingMapper { let assignmentClosure = { (jsonValue: Any?) -> Any? in if let _value = jsonValue{ if let object = _value as? NSObject { - if let str = String.transform(from: object){ + if let str = String.transform(from: object, transformer: transformer){ return _converter(str) } } diff --git a/Source/Serializer.swift b/Source/Serializer.swift index e05f563..9820baf 100644 --- a/Source/Serializer.swift +++ b/Source/Serializer.swift @@ -25,16 +25,16 @@ import Foundation public extension HandyJSON { - func toJSON() -> [String: Any]? { - if let dict = Self._serializeAny(object: self) as? [String: Any] { + func toJSON(transformer: _Transformer? = nil) -> [String: Any]? { + if let dict = Self._serializeAny(object: self, transformer: transformer) as? [String: Any] { return dict } return nil } - func toJSONString(prettyPrint: Bool = false) -> String? { + func toJSONString(prettyPrint: Bool = false, transformer: _Transformer? = nil) -> String? { - if let anyObject = self.toJSON() { + if let anyObject = self.toJSON(transformer: transformer) { if JSONSerialization.isValidJSONObject(anyObject) { do { let jsonData: Data @@ -57,13 +57,13 @@ public extension HandyJSON { public extension Collection where Iterator.Element: HandyJSON { - func toJSON() -> [[String: Any]?] { - return self.map{ $0.toJSON() } + func toJSON(transformer: _Transformer? = nil) -> [[String: Any]?] { + return self.map{ $0.toJSON(transformer: transformer) } } - func toJSONString(prettyPrint: Bool = false) -> String? { + func toJSONString(prettyPrint: Bool = false, transformer: _Transformer? = nil) -> String? { - let anyArray = self.toJSON() + let anyArray = self.toJSON(transformer: transformer) if JSONSerialization.isValidJSONObject(anyArray) { do { let jsonData: Data @@ -77,7 +77,7 @@ public extension Collection where Iterator.Element: HandyJSON { InternalLogger.logError(error) } } else { - InternalLogger.logDebug("\(self.toJSON()) is not a valid JSON Object") + InternalLogger.logDebug("\(self.toJSON(transformer: transformer)) is not a valid JSON Object") } return nil } diff --git a/Source/Transformable.swift b/Source/Transformable.swift index d03bb31..c996632 100644 --- a/Source/Transformable.swift +++ b/Source/Transformable.swift @@ -12,38 +12,38 @@ public protocol _Transformable: _Measurable {} extension _Transformable { - static func transform(from object: Any) -> Self? { + public static func transform(from object: Any, transformer: _Transformer?) -> Self? { if let typedObject = object as? Self { return typedObject } switch self { case let type as _ExtendCustomBasicType.Type: - return type._transform(from: object) as? Self + return type._transform(from: object, transformer: transformer) as? Self case let type as _BuiltInBridgeType.Type: - return type._transform(from: object) as? Self + return type._transform(from: object, transformer: transformer) as? Self case let type as _BuiltInBasicType.Type: - return type._transform(from: object) as? Self + return type._transform(from: object, transformer: transformer) as? Self case let type as _RawEnumProtocol.Type: - return type._transform(from: object) as? Self + return type._transform(from: object, transformer: transformer) as? Self case let type as _ExtendCustomModelType.Type: - return type._transform(from: object) as? Self + return type._transform(from: object, transformer: transformer) as? Self default: return nil } } - func plainValue() -> Any? { + public func plainValue(transformer: _Transformer?) -> Any? { switch self { case let rawValue as _ExtendCustomBasicType: - return rawValue._plainValue() + return rawValue._plainValue(transformer: transformer) case let rawValue as _BuiltInBridgeType: - return rawValue._plainValue() + return rawValue._plainValue(transformer: transformer) case let rawValue as _BuiltInBasicType: - return rawValue._plainValue() + return rawValue._plainValue(transformer: transformer) case let rawValue as _RawEnumProtocol: - return rawValue._plainValue() + return rawValue._plainValue(transformer: transformer) case let rawValue as _ExtendCustomModelType: - return rawValue._plainValue() + return rawValue._plainValue(transformer: transformer) default: return nil }