gpt4 book ai didi

ios - swift 2 : error when try to find with indexOf

转载 作者:可可西里 更新时间:2023-11-01 00:09:10 25 4
gpt4 key购买 nike

在全局变量部分我有这个声明

var friends:NSArray = NSMutableArray() // because i use them to share data into two segues

这是我的 tableView 函数的起始代码:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

self.tableView.deselectRowAtIndexPath(indexPath, animated: true)

let cell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
let user:PFUser = allUsers.objectAtIndex(indexPath.row) as! PFUser

if(isFriend(user)) {
// remove friend

// 1) Remove the Checkmark
cell.accessoryType = .None

// 2) Remove from Array list of friends

for friend in self.friends {
if friend.objectId == user.objectId {
if let foundIndex = friends.indexOf(friend) {

//remove the item at the found index
self.friends!.removeAtIndex(foundIndex)
}
}
}

// 3) Remove from backend

}
...
}

我尝试在 friend 列表中找到点击的 friend 的索引,以将 friend 添加或删除到数组“ friend ”中:

if let foundIndex = friends.indexOf(friend)

此行出现红色警报:NSArray 类型的值没有成员 indexOF

最佳答案

NSArray 或 NSMutableArray 与 Swift 原生数组(具有 indexOf 功能)不同。

尝试做:

let foundIndex = friends.indexOfObject(friend)
if foundIndex != NSNotFound {
// do something with the found index...
}

关于ios - swift 2 : error when try to find with indexOf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34843845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com