Cannot invoke 'append' with an argument list of type '(String?!)'

前端 未结 2 1819
傲寒
傲寒 2021-01-21 10:51

I\'m trying to add usernames from Parse in an array to display them in a UITableView, but get an error when I\'m appending the usernames to my array.

The error I get is:

2条回答
  •  轮回少年
    2021-01-21 11:39

    I solved my problem. I declare the array as an empty array and for unwrap the optional with the following code:

    var usernames = [String]()
    
    self.usernames.removeAll(keepCapacity: true)
    
        for fetchedUser in fetchedUsers! {
            if let username = fetchedUser.username as String! {
                self.usernames.append(username)
            }
        }
    

提交回复
热议问题