Created
April 11, 2019 10:53
-
-
Save anzfactory/9cb441895357e1d0d964d4d27bda0893 to your computer and use it in GitHub Desktop.
Swift で Optional 型のやつを文字列に埋め込んだときの出力を変える
This file contains hidden or 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
let text: String = "nullable" | |
let num: Int? = nil | |
print("text: \(text) num: \(num)") | |
/* output | |
> text: nullable num: | |
*/ |
This file contains hidden or 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
extension String.StringInterpolation { | |
mutating func appendInterpolation(_ value: CustomStringConvertible?) { | |
guard let value = value else { | |
return | |
} | |
appendLiteral(String(describing: value)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment