无法使用类型为“(字符串?!)"的参数列表调用“追加" [英] Cannot invoke 'append' with an argument list of type '(String?!)'
本文介绍了无法使用类型为“(字符串?!)"的参数列表调用“追加"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 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.
我得到的错误是:无法使用类型为(字符串?!)"的参数列表调用追加"
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)
}
}
这篇关于无法使用类型为“(字符串?!)"的参数列表调用“追加"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文