29
13

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.

SwiftUIの行儀の悪いお作法。

Last updated at Posted at 2019-09-19

SwiftUIとSwiftの強力な言語仕様を使うと怪しいことができます。

このようにStringIntViewに準拠させます。

extension String: View {
    public var body: some View {
        Text(self)
    }
}

extension Int: View {
    public var body: some View {
        Text("\(self)")
    }
}

そしてこう。

struct ContentView: View {
    var body: some View {
        VStack {

            "Hello World!"
                .foregroundColor(Color.green)

            1010001010

            111212

            29292
                .foregroundColor(Color.red)

            "ojowijojwe"
        }
    }
}

スクリーンショット 2019-09-19 13.11.14.png

😇
あまりいい作法とは言えないと思いますが、こんなこともできますよ。って感じで紹介しました。


次の記事もオススメです。

29
13
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
29
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?