i want ask how to grouping data (section) by Date?
there is my code :
import UIKit
import CoreData
class TableViewController: UITableViewController {
var myList = []
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
let appDel : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context : NSManagedObjectContext = appDel.managedObjectContext!
let freq = NSFetchRequest(entityName: "Item")
myList = context.executeFetchRequest(freq, error: nil)!
tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myList.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell
var object : NSManagedObject = myList[indexPath.row] as! NSManagedObject
let name = object.valueForKeyPath("name") as! String
let qty = object.valueForKeyPath("qty") as! Int
let date = object.valueForKeyPath("date") as! String
cell.nameLabel.text = name
cell.qtyLabel.text = toString(qty)
cell.dateLabel.text = date
return cell
}
}
in detail :
at now my date sample is just row (just 1 section default)
example :
apple 1 Jul 10, 2015 (row 1)
orange 7 Jul 10, 2015 (row 2)
grape 5 Jul 11, 2015 (row 3)
i want grouping by date so this result like :
Jul 11, 2015 (section 1)
grape 5 (row 1)
Jul 10, 2015 (section 2)
apple 1 (row 2)
orange 7 (row 3)
NB : section is dynamic, depends at data, and sorting date descending
anyone have solution? thx before