LoginSignup
0
0

More than 1 year has passed since last update.

【SwiftUI】ForEachの警告について

Posted at

該当コード

import SwiftUI

struct ContentView: View {
    let fruitArray: [String] = ["りんご", "みかん", "ぶどう", "いちご", "ばなな"]
    var body: some View {
        ForEach(0..<fruitArray.count) { index in
            Text(fruitArray[index])
        }
    }
}

スクリーンショット 2022-06-04 14.44.54.png

警告文

Non-constant range: argument must be an integer literal

解決策

ForEachidを設定する

import SwiftUI

struct ContentView: View {
    let fruitArray: [String] = ["りんご", "みかん", "ぶどう", "いちご", "ばなな"]
    var body: some View {
        ForEach(0..<fruitArray.count, id: \.self) { index in
            Text(fruitArray[index])
        }
    }
}

スクリーンショット 2022-06-04 14.46.13.png

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