I am making a Grocery list and so far I only have an array with the grocery list items. I want to add " today" at the top, "weekly" after three grocery items and "monthly" before the last three grocery items.
My question is, how would i specify where to insert cells from arrayNum2 which will be " today, weekly and monthly" with the grocery list?
Ex:
( Today )
item
item
item
Weekly
item
item
item
Monthly
item
item
item
Here is the code I have
//
import UIKit
class ViewController: UITableViewController{
var groceries = [Grocery]()
override func viewDidLoad() {
super.viewDidLoad()
self.groceries = [Grocery( name: "Lemon"), Grocery( name: "Bread"), Grocery( name: "Milk"),Grocery( name: "Tomato"),Grocery( name: "Pasta"),Grocery( name: "Soup"),Grocery( name: "Coke"),Grocery( name: "Potato"),Grocery( name: "Chips")]
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.groceries.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
var grocery : Grocery
grocery = groceries[indexPath.row]
cell.textLabel?.text = grocery.name
return cell
}
}
and my Grocery.swift
import Foundation
struct Grocery {
let name: String
}