add mapping transform extension

This commit is contained in:
Ivan Smolin 2017-06-09 10:02:54 +03:00
parent d76825deb5
commit 629830e64e
2 changed files with 65 additions and 0 deletions

View File

@ -360,6 +360,10 @@
6771DFE51EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE31EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift */; };
6771DFE61EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE31EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift */; };
6771DFE71EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE31EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift */; };
6771DFEA1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */; };
6771DFEB1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */; };
6771DFEC1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */; };
6771DFED1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */; };
6782BBA91EB31D5A0086E0B8 /* LeadKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6782BBA01EB31D590086E0B8 /* LeadKit.framework */; };
67952C3C1EB3266100B3BA1A /* LeadKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 67186B201EB247A200CFAFFB /* LeadKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
67952C3D1EB3266200B3BA1A /* LeadKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 67186B201EB247A200CFAFFB /* LeadKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -542,6 +546,7 @@
6771DFD71EE99EBA002DCDAE /* DateFormattingService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateFormattingService.swift; sourceTree = "<group>"; };
6771DFDD1EE99F6F002DCDAE /* DateFormattingArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateFormattingArguments.swift; sourceTree = "<group>"; };
6771DFE31EE9A00A002DCDAE /* DateFormattingArguments+DateFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateFormattingArguments+DateFormatter.swift"; sourceTree = "<group>"; };
6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateFormattingService+MappingTransform.swift"; sourceTree = "<group>"; };
6782BB911EB31CFE0086E0B8 /* LeadKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LeadKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6782BBA01EB31D590086E0B8 /* LeadKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LeadKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6782BBA81EB31D5A0086E0B8 /* LeadKit tvOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "LeadKit tvOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
@ -730,6 +735,7 @@
671461E51EB3396E00EAB194 /* CGSize */,
671461E81EB3396E00EAB194 /* CursorType */,
6771DFE21EE99FF3002DCDAE /* DateFormattingArguments */,
6771DFE81EEA7C8F002DCDAE /* DateFormattingService */,
671461EA1EB3396E00EAB194 /* Double */,
671461EC1EB3396E00EAB194 /* IndexPath */,
6714639C1EB33AC200EAB194 /* NetworkService */,
@ -1152,6 +1158,14 @@
path = DateFormattingArguments;
sourceTree = "<group>";
};
6771DFE81EEA7C8F002DCDAE /* DateFormattingService */ = {
isa = PBXGroup;
children = (
6771DFE91EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift */,
);
path = DateFormattingService;
sourceTree = "<group>";
};
67A1FF921EBCA64A00D6C89F /* CABasicAnimation */ = {
isa = PBXGroup;
children = (
@ -2005,6 +2019,7 @@
671463701EB3396E00EAB194 /* ApiRequestParameters.swift in Sources */,
671462EC1EB3396E00EAB194 /* UIImage+Extensions.swift in Sources */,
6714636C1EB3396E00EAB194 /* XibNameProtocol.swift in Sources */,
6771DFEA1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */,
671462A41EB3396E00EAB194 /* IndexPath+ImmutableIndexPath.swift in Sources */,
671462BC1EB3396E00EAB194 /* StoryboardProtocol+DefaultBundle.swift in Sources */,
671462A01EB3396E00EAB194 /* Double+Rounding.swift in Sources */,
@ -2080,6 +2095,7 @@
6771DFE01EE99F6F002DCDAE /* DateFormattingArguments.swift in Sources */,
671462AA1EB3396E00EAB194 /* ImmutableMappable+ObservableMappable.swift in Sources */,
671463621EB3396E00EAB194 /* SupportProtocol.swift in Sources */,
6771DFEC1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */,
671462861EB3396E00EAB194 /* CGContext+Initializers.swift in Sources */,
671463221EB3396E00EAB194 /* Any+Cast.swift in Sources */,
6714634E1EB3396E00EAB194 /* ReuseIdentifierProtocol.swift in Sources */,
@ -2186,6 +2202,7 @@
6714625B1EB3396E00EAB194 /* Log.swift in Sources */,
6714627B1EB3396E00EAB194 /* ResizeContentMode.swift in Sources */,
671463071EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */,
6771DFED1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */,
EFBE57E31EC362470040E00A /* AlertRepresentable.swift in Sources */,
671463A91EB340C000EAB194 /* UIViewController+ConfigurableController.swift in Sources */,
671463731EB3396E00EAB194 /* ApiRequestParameters.swift in Sources */,
@ -2259,6 +2276,7 @@
671462E51EB3396E00EAB194 /* UIColor+Hex.swift in Sources */,
671462CD1EB3396E00EAB194 /* String+SizeCalculation.swift in Sources */,
6771DFDF1EE99F6F002DCDAE /* DateFormattingArguments.swift in Sources */,
6771DFEB1EEA7CB8002DCDAE /* DateFormattingService+MappingTransform.swift in Sources */,
67A1FF951EBCA65E00D6C89F /* CABasicAnimation+Rotation.swift in Sources */,
671462811EB3396E00EAB194 /* AlamofireRequest+Extensions.swift in Sources */,
671462C51EB3396E00EAB194 /* String+Extensions.swift in Sources */,

View File

@ -0,0 +1,47 @@
//
// Copyright (c) 2017 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import ObjectMapper
public extension DateFormattingService {
/// Creates transform for date to string and string to date mapping.
///
/// - Parameter arguments: A formatting arguments structure.
/// - Returns: A transform for given formatting arguments.
func mappingTransform(for arguments: DateFormattingArguments) -> TransformOf<Date, String> {
return TransformOf<Date, String>(fromJSON: { stringValue in
if let stringValue = stringValue {
return self.date(from: stringValue, arguments: arguments)
} else {
return nil
}
}, toJSON: { dateValue in
if let dateValue = dateValue {
return self.string(from: dateValue, arguments: arguments)
} else {
return nil
}
})
}
}