【发布时间】:2020-09-27 06:26:52
【问题描述】:
The solution 帮助我避免空数组,但不能让我提取数组 [0] 旁边的值。
在将所有值附加到数组后,我想提取 2 个值。
array[0] 打印成功,但当我尝试打印 array1 时,错误消息显示为“索引超出范围”。
下面是代码:
var followingList = [User]()
func fetchfollowingList(callback: @escaping ([User]) -> Void) {
API.User.fetchFollowingList { followingUser in
self.followingList.append(followingUser)
callback(self.followingList)
print(self.followingList)
}
print(self.followingList[0].displayName)
print(self.followingList[1].displayName)
}
“打印(self.followingList)”结果在控制台:
[APP01.User]
[APP01.User, APP01.User]
[APP01.User, APP01.User, APP01.User]
我推断 array1 是从仅附加一个值的第一个数组中提取的,而不是从附加所有值的 第三个数组 中提取的,并且不知道如何修复它。
谢谢
【问题讨论】:
-
这能回答你的问题吗? Why it print out an empty array instead of the array appended with values for the first time in viewDidLoad()?。你已经问过这个问题并得到了这个问题的答案。
-
The answer 帮助我避免空数组,但不能让我提取数组[0]之外的值。