命令因信号错误而失败 - Swift 2.2 Xcode 7.3

Command Failed Due To Signal Fault - Swift 2.2 Xcode 7.3

更新到 xcode 7.3 后,我正在更新我所有的 swift 语法 在这个过程中,我得到了一些关于 ambiguous use of subscript swift 的错误,我相信这个错误也是导致信号错误的原因。

有问题的代码:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var arry:NSArray = Array(self.participants)
         arry = arry.sort {
         item1, item2 in
         // ambiguous use of subscript swift error for both these lines
         let date1 = item1["fullName"] as String
         let date2 = item2["fullName"] as String
         return date1 > date2
    }

编辑

participants 的声明来自此处的另一个控制器:

        func gotoMembers(){

        let set:NSSet = self.conversation.participants
        let arr = set.allObjects //Swift Array
        UserManager.sharedManager.queryForAllUsersWithCompletion(arr as! [String], completion:{ (users: NSArray?, error: NSError?) in
            if error == nil {
               //participants declared here and passed into the participant controller
                let participants = NSSet(array: users as! [PFUser]) as Set<NSObject>
                let controller = ParticipantTableViewController(participants: participants, sortType: ATLParticipantPickerSortType.FirstName)
                controller.delegate = self
                self.navigationController?.pushViewController(controller, animated:true);
            } else {
                appDelegate.log.error("Error querying for All Users: \(error)")
            }
        })

    }

更新

首先尽可能使用Swift原生类型,例如NSArray对象内容的类型是未指定的。

其次尽量少用类型注解,在这种情况下

var array = Array(self.participants)

如果没有注解,你会免费得到一个 Swift Array,编译器知道内容的类型是 PFUser。函数 sortInPlace() 在没有 return 值的情况下对数组本身进行排序,您必须强制将 fullName 值向下转换为 String

     array.sortInPlace {
        user1, user2 in

        let date1 = user1["fullName"] as! String
        let date2 = user2["fullName"] as! String
        return date1 > date2
}

并在完成处理程序中使用正确的类型 Set<PFUser> 而不是 Set<NSObject> 并且可能 users: [PFUser]? 而不是 users: NSArray?

编辑:queryForAllUsersWithCompletion 方法的开头应该看起来像

UserManager.sharedManager.queryForAllUsersWithCompletion(arr as! [String], completion:{ (users: [PFUser]?, error: NSError?) in
    if error == nil {
       //participants declared here and passed into the participant controller
       let participants = Set<PFUser>(array: users!)