错误:无法find接受提供参数的“title”的重载

目前我有NSManaged对象的子类称为Folder属性称为itemtypesNSSet 。 我有一个函数返回一个NSMutableArray ,我试图在tableview中显示数据(然后重新排列表中显示的顺序)。

 class Folder: NSManagedObject { @NSManaged var title: String @NSManaged var date: NSDate @NSManaged var item: NSSet func itemMutableArray() -> NSMutableArray { return NSMutableArray(array: (item.allObjects as! [Checklist]).sorted{ $0.date.compare($1.date) == NSComparisonResult.OrderedAscending } ) } 

TableViewController:

  var itemMutableArray: NSMutableArray! itemMutableArray = folder.itemMutableArray() cell.textLabel?.text = itemMutableArray[indexPath.row].title //Error 

不幸的是,当使用这个函数时,这在我的tableview中返回一个错误。

错误无法find接受提供的参数的“标题”的重载

最终我试图实现的是显示数据并移动单元格来改变NSSet的顺序。

  table.didMoveCellFromIndexPathToIndexPathBlock = {(fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) -> Void in let delegate:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let context: NSManagedObjectContext = delegate.managedObjectContext! context.deleteObject(self.itemArray[indexPath!.row] as NSManagedObject ) self.itemArray.exchangeObjectAtIndex(toIndexPath.row, withObjectAtIndex: fromIndexPath.row) } 

PS:最初我有一个函数返回对象的数组,但我无法修改NSSet的顺序,因为它们没有sorting。

 func itemArray() -> [Item] { let sortDescriptor = NSSortDescriptor(key: "date", ascending: true) return item.sortedArrayUsingDescriptors([sortDescriptor]) as! [Item] } 

有没有人对我目前出错的地方有什么build议?

expression式itemMutableArray[indexPath.row].title的问题在于,因为您已经将itemMutableArraytypesitemMutableArray NSMutableArray, itemMutableArray[indexPath.row]是AnyObject。 因此,Swift没有理由相信这个东西有一个title属性。 你需要把它转换成具有title属性的东西(尽pipe如果可能的话,避免使用NSMutableArray会更好,因为Swift数组可变的)。