Swift 5:为什么会出现 Index out of range 错误?
发布时间:2022-07-29 15:48:36 354
相关标签: # react-native
我有两个数组,我将把它们包含在一个带有对象实例的数组中。当我尝试执行此操作时,我收到索引超出范围的错误。
我的代码如下。我不知道为什么我会收到这个错误。有人可以让我知道我做错了什么吗?
import UIKit
let mealName = ["Breakfast", "Lunch", "Dinner", "Breakfast", "Lunch", "Dinner", "Breakfast", "Lunch", "Dinner", "Snack", "Supper", "Snack", "Breakfast", "Snack", "Lunch", "Dinner", "Supper", "Snack", "Breakfast", "Snack", "Dinner", "Snack", "Snack", "Snack", "Breakfast", "Snack", "Lunch", "Snack", "Snack", "Snack", "Breakfast", "Snack", "Lunch", "Snack", "Snack", "Snack", "Snack"]
let mealCalories = [725.03, 539.44, 849.49, 956.53, 267.18, 567.17, 353.47, 387.12, 700.76, 62.87, 857.35, 176.56, 123.79, 16.74, 813.74, 858.23, 127.26, 448.19, 932.62, 60.22, 880.55, 58.85, 78.48, 21.5, 564.74, 190.75, 911.01, 67.47, 81.44, 25.35, 954.94, 45.75, 858.71, 61.7, 189.75, 72.54, 75.84]
struct Meal {
var mealName: String
var mealCalories: Double
}
var meals = [Meal]()
for i in 0..<37 {
meals[i].mealName = mealName[i]
meals[i].mealCalories = mealCalories[i]
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报