The solution help me avoid the empty array but can't let me extract values beside array[0].
I'd like to extract 2 values after appending all values to the array.
array[0] is printed out successfully but the error message appeared as "Index out of range" while I tried to print out array1.
below is the code:
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)
}
the "print(self.followingList)" result in console:
[APP01.User]
[APP01.User, APP01.User]
[APP01.User, APP01.User, APP01.User]
I inferred that the array1 is being extracted from the 1st array appended with only one value instead of the 3rd array appended with all values and not knowing how to fix it.
thanks