0
0

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 1 year has passed since last update.

【SwiftUI】Extra argument in callの対処法

Last updated at Posted at 2022-06-11

はじめに

Extra argument in callはSwiftUIにはあるあるで、よく発生します。

原因

SwiftUIはView要素を9個以上追加できないようになっています。
スクリーンショット 2022-06-11 15.37.30.png

解決策

ViewをGroupでグループ化して要素をまとめます。

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Group {
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
                Text("Hello, world!")
            }

            Group {
                Text("Hello, world!")
            }

        }
    }
}

これでエラーは出なくなります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?