无法使用类型为((String ?!))的参数列表调用'append'

编程入门 行业动态 更新时间:2024-10-28 21:16:11
本文介绍了无法使用类型为((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'

本文发布于:2023-11-26 16:32:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   类型   列表   append   String

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!