我有错误 (shoppingList.lastObject)
var shoppingList = ["bananas", "milk", "vanilla ice cream"]
var itemCount = shoppingList.count
print("There are \(itemCount) items.")
for item in shoppingList
{
print("I need to buy \(item).")
}
print("The most important item on my list is definitely \(shoppingList.lastObject)")
它说 lastObject 不是成员。
最佳答案
它是last
而不是lastObject
:
var shoppingList = ["bananas", "milk", "vanilla ice cream"]
var itemCount = shoppingList.count
print("There are \(itemCount) items.")
for item in shoppingList {
print("I need to buy \(item).")
}
print("The most important item on my list is definitely \(shoppingList.last)")
注意:使用.first
获取第一个元素。
关于ios - 类型 '[String]' 的值没有成员 'lastObject',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909824/