Created
October 17, 2020 08:34
-
-
Save IsaAliev/feb7c2d394a32a2ffd29974815387c04 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
protocol CollectionItemsViewModelDependencyManager { | |
var dependencies: [ViewDependency] { get } | |
func mapModelTypeNameToIdentifier(_ fullTypeName: String) -> String | |
func reuseIdentifier(for model: CollectionItemViewModel) -> String | |
func resolveIdentifier(forModelTypeUsingUnusualNaming fullTypeName: String) -> String | |
} | |
extension CollectionItemsViewModelDependencyManager { | |
func reuseIdentifier(for model: CollectionItemViewModel) -> String { | |
let typeName = String(describing: type(of: model)) | |
return mapModelTypeNameToIdentifier(typeName) | |
} | |
func mapModelTypeNameToIdentifier(_ fullTypeName: String) -> String { | |
guard fullTypeName.hasSuffix("Model") else { | |
return resolveIdentifier(forModelTypeUsingUnusualNaming: fullTypeName) | |
} | |
let typeName = String(fullTypeName.split(separator: ".").last!) | |
let modelTailTrimmedName = typeName.dropLast(5) | |
return String(modelTailTrimmedName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment