Q:

Trying to return each index of my array inside my UITableView

I am trying to use the MVC model in my app. This is the first time I am using it as I am just learning iOS programming. There are several things you need to know to help me. First: I have a model called Home.swift inside this model I have an array and a function. "Home.swift": 
class Home: NSObject {
  var content: [String] = [
    "Apple",
    "Door",
    "Evil",
    "Error",
]
func homeDisplayContent() -> String  {
    for var i = 0; i < 12; i++ {
        return content[i]
    }
}
}

Do I need an init in here, if so how would I implement it? Secondly, I have a View for my tableView. I don't think anything is wrong with my view. But just in case inside here I have my "HomeCell.swift": 
    var homes: Home! {
    didSet{
        contentLabel.text = homes.homeContent()
    }
}

Lastly I have my view controller, "HomePageViewController.swift":
var homes: [Home]!

@IBOutlet weak var homeTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.homeTableView.delegate = self
    self.homeTableView.dataSource = self
    homes = [Home()]
    self.homeTableView.reloadData()
    // Do any additional setup after loading the view.
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as? HomeCell
    cell!.homes = homes[indexPath.row]

    return cell!
}

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

What I want to do is be able to grab each index inside my array inside the Home.swift (My model) and present them in their own individual cells. I believe I need to create an array of Home objects but I am not sure how to go about doing this. Sorry for the block of text and for poor formatting (cannot for the life of me fix the first block of code) but I am really lost and have looked around on google and stackoverflow for awhile trying to figure out my problem with no luck. Thanks in advance!

A:

You are hard-coding the values in contents array. So you need to use the values from that array. There is no need to create multiple Home object in this case. You want something like:
Home.swift
class Home : NSObject
{
   var content: [String] = [
     "Apple",
     "Door",
     "Evil",
     "Error",
   ]

   func homeDisplayContent(atIndex : Int) -> String
   {
       return content[atIndex]
   }
}

HomePageViewController.swift
var home = Home()
@IBOutlet weak var homeTableView: UITableView!

override func viewDidLoad()
{
    super.viewDidLoad()

    self.homeTableView.delegate   = self
    self.homeTableView.dataSource = self
    self.homeTableView.reloadData()
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as! HomeCell
    cell.contentLabel.text = home.homeDisplayContent(indexPath.row)
    return cell
}

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

