本文介绍了无法使用类型为((String ?!))的参数列表调用'append'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从数组中的Parse添加用户名以在UITableView中显示它们,但是在将用户名附加到数组中时出现错误.
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.
我得到的错误是:无法用'(String ?!)'类型的参数列表调用'append'
The error I get is: Cannot invoke 'append' with an argument list of type '(String?!)'
我在做什么错了?
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) } }推荐答案
我解决了我的问题.我将数组声明为空数组,并使用以下代码解开可选数组:
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) } }更多推荐
无法使用类型为((String ?!))的参数列表调用'append'
发布评论