123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- internal final class FromJSON {
-
-
- class func basicType<FieldType>(_ field: inout FieldType, object: FieldType?) {
- if let value = object {
- field = value
- }
- }
-
-
- class func optionalBasicType<FieldType>(_ field: inout FieldType?, object: FieldType?) {
- field = object
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalBasicType<FieldType>(_ field: inout FieldType!, object: FieldType?) {
- field = object
- }
- #endif
-
-
- class func object<N: BaseMappable>(_ field: inout N, map: Map) {
- if map.toObject {
- field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: field)
- } else if let value: N = Mapper(context: map.context).map(JSONObject: map.currentValue) {
- field = value
- }
- }
-
-
- class func optionalObject<N: BaseMappable>(_ field: inout N?, map: Map) {
- if let f = field , map.toObject && map.currentValue != nil {
- field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f)
- } else {
- field = Mapper(context: map.context).map(JSONObject: map.currentValue)
- }
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalObject<N: BaseMappable>(_ field: inout N!, map: Map) {
- if let f = field , map.toObject && map.currentValue != nil {
- field = Mapper(context: map.context).map(JSONObject: map.currentValue, toObject: f)
- } else {
- field = Mapper(context: map.context).map(JSONObject: map.currentValue)
- }
- }
- #endif
-
-
- class func objectArray<N: BaseMappable>(_ field: inout Array<N>, map: Map) {
- if let objects = Mapper<N>(context: map.context).mapArray(JSONObject: map.currentValue) {
- field = objects
- }
- }
-
-
- class func optionalObjectArray<N: BaseMappable>(_ field: inout Array<N>?, map: Map) {
- if let objects: Array<N> = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) {
- field = objects
- } else {
- field = nil
- }
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalObjectArray<N: BaseMappable>(_ field: inout Array<N>!, map: Map) {
- if let objects: Array<N> = Mapper(context: map.context).mapArray(JSONObject: map.currentValue) {
- field = objects
- } else {
- field = nil
- }
- }
- #endif
-
-
- class func twoDimensionalObjectArray<N: BaseMappable>(_ field: inout Array<Array<N>>, map: Map) {
- if let objects = Mapper<N>(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue) {
- field = objects
- }
- }
-
-
- class func optionalTwoDimensionalObjectArray<N: BaseMappable>(_ field: inout Array<Array<N>>?, map: Map) {
- field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue)
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalTwoDimensionalObjectArray<N: BaseMappable>(_ field: inout Array<Array<N>>!, map: Map) {
- field = Mapper(context: map.context).mapArrayOfArrays(JSONObject: map.currentValue)
- }
- #endif
-
-
- class func objectDictionary<N: BaseMappable>(_ field: inout Dictionary<String, N>, map: Map) {
- if map.toObject {
- field = Mapper<N>(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: field)
- } else {
- if let objects = Mapper<N>(context: map.context).mapDictionary(JSONObject: map.currentValue) {
- field = objects
- }
- }
- }
-
-
- class func optionalObjectDictionary<N: BaseMappable>(_ field: inout Dictionary<String, N>?, map: Map) {
- if let f = field , map.toObject && map.currentValue != nil {
- field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f)
- } else {
- field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue)
- }
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalObjectDictionary<N: BaseMappable>(_ field: inout Dictionary<String, N>!, map: Map) {
- if let f = field , map.toObject && map.currentValue != nil {
- field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue, toDictionary: f)
- } else {
- field = Mapper(context: map.context).mapDictionary(JSONObject: map.currentValue)
- }
- }
- #endif
-
-
- class func objectDictionaryOfArrays<N: BaseMappable>(_ field: inout Dictionary<String, [N]>, map: Map) {
- if let objects = Mapper<N>(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue) {
- field = objects
- }
- }
-
-
- class func optionalObjectDictionaryOfArrays<N: BaseMappable>(_ field: inout Dictionary<String, [N]>?, map: Map) {
- field = Mapper<N>(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue)
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalObjectDictionaryOfArrays<N: BaseMappable>(_ field: inout Dictionary<String, [N]>!, map: Map) {
- field = Mapper<N>(context: map.context).mapDictionaryOfArrays(JSONObject: map.currentValue)
- }
- #endif
-
-
- class func objectSet<N: BaseMappable>(_ field: inout Set<N>, map: Map) {
- if let objects = Mapper<N>(context: map.context).mapSet(JSONObject: map.currentValue) {
- field = objects
- }
- }
-
-
- class func optionalObjectSet<N: BaseMappable>(_ field: inout Set<N>?, map: Map) {
- field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue)
- }
-
-
- #if !(swift(>=4.1.50) || (swift(>=3.4) && !swift(>=4.0)))
-
- class func optionalObjectSet<N: BaseMappable>(_ field: inout Set<N>!, map: Map) {
- field = Mapper(context: map.context).mapSet(JSONObject: map.currentValue)
- }
- #endif
- }
|