2

I'm fairly new to Swift and I've been trying to pull individual items from an array stored in Parse.com

When printing the array itself, I get all the users, however, when attempting to get the first index of an array I get the following error

"fatal error: Cannot index empty buffer"

This is code I'm currently using -

import UIKit
import Parse
class feedTableViewController: UITableViewController {
  var titles = [String]()
  var usernames = [String]()
  var images = [UIImage]()
  var imageFiles = [PFFile]()

  override func viewDidLoad() {
    super.viewDidLoad()
    //....
  }

  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var myCell:cell = self.tableView.dequeueReusableCellWithIdentifier("myCell") as cell
    //Error occurs here - does not work due to empty buffer
    myCell.title.text = titles[indexPath.row]
    myCell.username.text = usernames[indexPath.row]
    //If the previous two lines are commented out, I can print out both the arrays
    println(titles)
    println(usernames)

    return myCell
  }
}

Thanks!

4
  • 1
    Please reduce your code to a Minimal, Complete, and Verifiable example. Please also specify on which line the error you quoted occurs. Commented Jun 23, 2015 at 15:51
  • @AaronBrager I have reduced the code and narrowed down to where the error is displayed on xCode. Though I would've thought that the removed code may have helped others understand the code better? Thanks Commented Jun 23, 2015 at 16:05
  • Does println(titles[indexPath.row]) print what you expect? titles may be empty, or may have fewer elements than you return in numberOfRowsInSection Commented Jun 23, 2015 at 16:22
  • @AaronBrager No it doesn't. It gives me the same error when printed out. However, I currently feel like crying. numberOfRowsInSection was the culprit. It wasn't calling the number of items of the array, rather a set number. Thanks Aaron. Much appreciated. You have NO idea how long I've spent trying to fix this..... Commented Jun 23, 2015 at 16:53

1 Answer 1

1

Make sure the number of elements in titles matches the number you return in numberOfRowsInSection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.