4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swiftでクラス名をStringで取得する。

Last updated at Posted at 2017-08-25

StoryboardのIdentifierとかを手書きしたりするとたまにあるタイプミス。
極力そういうのを減らしたい。できればプロパティで取得したい。
そんなわけで色々いじってたらこうなりました。

protocol getClassName {
}

extension getClassName {
    static var className: String {
        
        return String(describing: self)
    }
}

extension NSObject: getClassName { }

使う時はこんな感じでよくなりました。

UIViewContiosroller.className

enjoy Swift!

4
4
2

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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?