Created
December 13, 2019 14:06
-
-
Save aprofromindia/a9ba4be5f8e4ae6354b4e2b0289255ab to your computer and use it in GitHub Desktop.
Optional String conversion gists
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
// | |
// Optional+String.swift | |
// | |
// Created by Apro on 13/12/19. | |
// | |
import Foundation | |
extension Optional where Wrapped: Numeric & LosslessStringConvertible { | |
func stringOrEmpty() -> String { | |
if let self = self { | |
return String(self) | |
} | |
return "" | |
} | |
} | |
extension Optional where Wrapped == Date { | |
func stringOrEmpty(formatter: DateFormatter) -> String { | |
if let self = self { | |
return formatter.string(from: self) | |
} | |
return "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment