【发布时间】:2016-04-24 18:01:50
【问题描述】:
我正在使用两个数组:
var facebookFriends: [FacebookFriend] = []
var friendsToInvite: [FacebookFriend]!
第一个数组包含所有 Facebook 好友,第二个数组包含对象 FacebookFriend,它们已在不同的 ViewController 中选择。
两个数组都在 ViewController 中正确实例化。
在-tableView:cellForRowAtIndexPath 委托方法中,如果facebookFriends 数组中的Facebook 好友包含在friendsToInvite 数组中,我想更改单元格视图。
为了实现这一点,我尝试了以下方法:
if(friendsToInvite.contains(facebookFriends[indexPath.row])) {
// Code to change the view of the cell
}
但我收到以下错误:
不能为“[FacebookFriend]”类型的值下标。
有没有其他方法可以检查这个对象是否包含在数组中?
【问题讨论】:
-
“[FacebookFriend]”中存储了什么样的值?
-
我创建了自己的类 `FacebookFriend`,并使用以下构造函数来创建对象:`init(facebookId: String, facebookUsername: String, profilePicture: NSData) { self.facebookId = facebookId self.facebookUsername = facebookUsername self.profilePicture = profilePicture } `
标签: ios arrays swift2 contains equality