LoginSignup
1
1

More than 5 years have passed since last update.

Optional(2018)年を小細工で避けてみる

Posted at

iOS界隈で

Optional(2018)年

というワードが流行り、ブームが過ぎ去った頃だと思いますが、今更ながら便乗してみました。


extension Optional: CustomStringConvertible {

    public var description: String {
        switch self {
        case .none:
            return ""

        case .some(let wrapped):
            return "\(wrapped)"
        }
    }
}

let year: Int? = 2018

print("\(year)年あけましておめでとうございます。") // 2018年あけましておめでとうございます。

要は、ユーザーに"Optional"という文字列を見せなければいいんですよ、という思想。


まぁOptional<Int>"\()"の中に入れようとした時点でwarning出ますけどね。¯\_(ツ)_/¯

スクリーンショット 2018-01-07 3.28.21.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1