Created
November 29, 2022 19:21
-
-
Save TsRebornz/0b022325006e006a61614a70ab7d91bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TableStructMapper<T> { | |
let sizeWidthdKeyPath: KeyPath<T, Int> | |
let sizeHeightKeyPath: KeyPath<T, Int> | |
let materialKeyPath: KeyPath<T, String> | |
func map(with mapper: T) -> Table { | |
return .init( | |
size: .init( | |
width: mapper[keyPath: sizeWidthdKeyPath], | |
height: mapper[keyPath: sizeHeightKeyPath] | |
), | |
material: .init(rawValue: mapper[keyPath: materialKeyPath])! // forceunwrap | |
) | |
} | |
} | |
let mapperNetworkModel = TableStructMapper( | |
sizeWidthdKeyPath: \TableDTO.width, | |
sizeHeightKeyPath: \TableDTO.height, | |
materialKeyPath: \TableDTO.material | |
) | |
let mappeCoredataModel = TableStructMapper( | |
sizeWidthdKeyPath: \TableEntity.width, | |
sizeHeightKeyPath: \TableEntity.height, | |
materialKeyPath: \TableEntity.material | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment