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

13,103

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)
        }
    }
Share:
13,103
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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: Cannot invoke 'append' with an argument list of type '(String?!)'

    What am I doing wrong?

    var usernames = [""]
    
    func updateUsers() {      
        var query = PFUser.query()
        query!.whereKey("username", notEqualTo: PFUser.currentUser()!.username!)
        var fetchedUsers = query!.findObjects()
    
        for fetchedUser in fetchedUsers! {
            self.usernames.append(fetchedUser.username)
        }
    }