Ios UITableView标题日期使用NSFetchedResultsController-Swift?

Ios UITableView标题日期使用NSFetchedResultsController-Swift?,ios,uitableview,date,swift,core-data,Ios,Uitableview,Date,Swift,Core Data,我正在从核心数据中提取字符串值,并将它们显示在UITableView中……它正在工作并显示所有条目。现在,我想按创建日期(也存储在核心数据中)对这些值进行“分组”,但我很难实现此分组标题…以下是我得到的: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var sound = self.sounds[in

我正在从核心数据中提取字符串值,并将它们显示在UITableView中……它正在工作并显示所有条目。现在,我想按创建日期(也存储在核心数据中)对这些值进行“分组”,但我很难实现此分组标题…以下是我得到的:

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var sound = self.sounds[indexPath.row]
        var cell = UITableViewCell()

        // Convert Date to String
        var formatter: NSDateFormatter = NSDateFormatter()
        formatter.dateFormat = "yyyy-MM-dd-HH-mm-ss"
        let dateTimePrefix: String = formatter.stringFromDate(sound.dateSaved)
        // Display the following in each rows
        cell.textLabel!.text = sound.name + " Saved: " + dateTimePrefix

        return cell
    }
有人能给我指出如何实现“头”的正确方向吗?我已经在Main.storyboard设置中将tableView设置为“分组”样式

---更新

感谢下面的回复,但不幸的是,这些例子都在Obj-C中,我正在为斯威夫特拍摄

为了扩展,我从核心数据中检索了以下数据,并在UITableView中显示了所有数据:

override func viewDidLoad() {
        super.viewDidLoad()

        self.tableView.dataSource = self
        self.tableView.delegate = self
}

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    var context = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext!
    var request = NSFetchRequest(entityName: "Sound")
    self.sounds = context.executeFetchRequest(request, error: nil)! as [Sound]
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.sounds.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
    var sound = self.sounds[indexPath.row]

    // Convert Date to String
    var formatter: NSDateFormatter = NSDateFormatter()
    formatter.dateFormat = "yyyy-MM-dd @ HH:mm:ss"
    let dateTimePrefix: String = formatter.stringFromDate(sound.dateSaved)
    // Display the following in each rows
    cell.textLabel!.text = sound.name // Sound Name
    // Display the following as each subtitles
    cell.detailTextLabel!.text = dateTimePrefix // Sound Duration (Currently 'date')

    return cell
}

有人能告诉我如何使用
sectionNameKeyPath
,使用“月”标题对每个月进行“分组”的正确方向吗?

您正在寻找
sectionNameKeyPath
,特别是基于日期计算的节标题